Showing posts with label Cross Platform App Development. Show all posts

.NET MAUI is a powerful platform for building cross-platform mobile applications, and with the right tools and resources, it'...

.Net MAUI - Zxing Barcode Scanner .Net MAUI - Zxing Barcode Scanner

A blog about android developement

Cross Platform App Development

.NET MAUI is a powerful platform for building cross-platform mobile applications, and with the right tools and resources, it's easy to add barcode scanning functionality to your app. In this tutorial, we'll walk you through the steps of implementing a barcode scanner in .NET MAUI using the ZXing.Net.MAUI plugin.

Quick Links:


Project Setup:

  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app

Implementation:

The successor to ZXing.Net.Mobile: barcode scanning and generation for .NET MAUI applications. First, we need to add the ZXing.Net.MAUI library to our project as a dependency. To do this, open the NuGet Package Manager and search for "ZXing.Net.MAUI". Install the package in your .NET MAUI project.

Install ZXing.Net.MAUI

Install ZXing.Net.MAUI NuGet package on your .NET MAUI application. Make sure to initialize the plugin first in your MauiProgram.cs, see below

// Add the using to the top
using ZXing.Net.Maui;

// ... other code 

public static MauiApp Create()
{
    var builder = MauiApp.CreateBuilder();
    builder
    .UseMauiApp<App>()
    .UseBarcodeReader(); // Make sure to add this line

return builder.Build();
}

Now we just need to add the right permissions to our app metadata. Find below how to do that for each platform.

Android

For Android go to your "AndroidManifest.xml" file (under the Platforms\Android folder) and add the following permissions inside of the "manifest" node.

<uses-permission android:name="android.permission.CAMERA" />

iOS

For iOS go to your "info.plist" file (under the Platforms\iOS folder) and add the following permissions inside of the "dict" node:

<key>NSCameraUsageDescription</key>
<string>This app uses barcode scanning to...</string>

Make sure that you enter a clear and valid reason for your app to access the camera. This description will be shown to the user.

Windows

Windows is not supported at this time for barcode scanning. You can however use the barcode generation. No extra permissions are required for that. For more information on permissions, see the Microsoft Docs.

Using ZXing.Net.Maui

If you're using the controls from XAML, make sure to add the right XML namespace in the root of your file, e.g:

xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI"
<zxing:CameraBarcodeReaderView
  x:Name="cameraBarcodeReaderView"
  BarcodesDetected="BarcodesDetected" />
Full Code of MainPage.xaml:

Configure Reader options

cameraBarcodeReaderView.Options = new BarcodeReaderOptions
{
  Formats = BarcodeFormats.OneDimensional,
  AutoRotate = true,
  Multiple = true
};

Toggle Torch

cameraBarcodeReaderView.IsTorchOn = !cameraBarcodeReaderView.IsTorchOn;

Flip between Rear/Front cameras

cameraBarcodeReaderView.CameraLocation
  = cameraBarcodeReaderView.CameraLocation == CameraLocation.Rear ? CameraLocation.Front : CameraLocation.Rear;

Handle detected barcode(s)

protected void BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
{
  foreach (var barcode in e.Results)
    Console.WriteLine($"Barcodes: {barcode.Format} -> {barcode.Value}");
}
Full code of MainPage.xaml.cs

Demo

Full Code:

Download Code:

You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

In this tutorial series, we will see how to manage the user subscription from the app as we are updating our Subscriptions policy ...

.Net MAUI - Manage Subscription in Android and iOS. .Net MAUI - Manage Subscription in Android and iOS.

A blog about android developement

Cross Platform App Development

In this tutorial series, we will see how to manage the user subscription from the app as we are updating our Subscriptions policy to state that users must be able to easily cancel their subscriptions from within the app.

Project Setup:

  • To create .NET MAUI apps, we need the latest Visual Studio 2022 installed with .NET Multi-platform App UI development workload with its default optional installation options in our PC or mac machine.
  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the Configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app

Implementation:

  • open the MainPage.xaml file and add the following button for subscription click
  • For Android, we can open the play store directly to specific app subscription if the sku and the app package name are known and the user is already subscribed. Also, we can open the subscription where all the non-exipry sucscribtions are listed.
  • For iOS, We have specific API to open the app page from the app. But we can open the apple support page "https://support.apple.com/HT202039"
  • This should also adhere to the app store guidelines.

Download Code:

You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

In this tutorial series, we will see the basic layout of sign-up screen using the MAUI controls in Visual Studio 2022 on Windows, ...

.Net Multi-Platform App UI - Registration Form .Net Multi-Platform App UI - Registration Form

A blog about android developement

Cross Platform App Development

In this tutorial series, we will see the basic layout of sign-up screen using the MAUI controls in Visual Studio 2022 on Windows, or Visual Studio 2022 for Mac 17.4 Preview.

Project Setup:

  • To create .NET MAUI apps, we need the latest Visual Studio 2022 installed with .NET Multi-platform App UI development workload with its default optional installation options in our PC or mac machine.
  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the Configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app

Implementation:

  • open the MainPage.xaml page designer file and add the following entries for email and password like below

Result:

Android

Windows

Download:

You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

In this tutorial series, we'll learn how to create and run your first .NET Multi-platform App UI (.NET MAUI) app in Visual Studio ...

.Net Multi-Platform App UI - MAUI Project Setup .Net Multi-Platform App UI - MAUI Project Setup

A blog about android developement

Cross Platform App Development

In this tutorial series, we'll learn how to create and run your first .NET Multi-platform App UI (.NET MAUI) app in Visual Studio 2022 on Windows, or Visual Studio 2022 for Mac 17.4 Preview.

Project Setup:

  • To create .NET MAUI apps, we need the latest Visual Studio 2022 installed with .NET Multi-platform App UI development workload with its default optional installation options in our PC or mac machine.
  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the Configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app
  • Visual Studio will build the app, and deploy the app to the emulator or device.
  • The sample app screen will be look like the below in Android, iOS and Windows.

    Android Output:

    iOS Output:

    Windows Output:

Introduction: In this tutorial, we will learn how to implement Multi-Lingual in Xamarin.Forms without using external plugins or platfor...

Multilingual Implementation - Xamarin.Forms Multilingual Implementation - Xamarin.Forms

A blog about android developement

Cross Platform App Development



Introduction:

In this tutorial, we will learn how to implement Multi-Lingual in Xamarin.Forms without using external plugins or platform wise implementation with dependency service. The latest Xamarin forms offers .net standard to implement the multilingual and without further delay, we will skip into the coding part of the article.

Coding Part:

Steps:

I have split the coding part into 4 steps as in the following.

  1. Creating new Xamarin.Forms Projects.
  2. Creating App Resource files for multi-language.
  3. Language Management
  4. Implementation of Multi-Lingual.

Step 1: Creating new Xamarin.Forms Projects

  • Create New Project by Selecting New -> Project -> Select Xamarin Cross Platform App and Click OK.
  • Then Select Android and iOS Platforms as shown below with Code Sharing Strategy as PCL or .Net Standard and Click OK.

Step 2: Creating App Resource files for multi-language

  • Add one resource file as base file with the name your preferred name. In my case, I kept the name of the file as “AppResources.resx” and it will be used as default language file.
  • Then add one resource file for each language you want to support. We must follow a specific naming convention for each file as the base resources file followed by a period (.) and then the language code.
  • For Example
    Language Language Code File Name
    Tamil ta AppResources.ta.resx
    French fr AppResources.fr.resx

  • Then add resources with the same name with language specific values in each resource files as like in the below screenshot.

Step 3: Language Management

In this step, we will see how to handle the multilingual for Xamarin.Forms.

  • Get Device Language
    CultureInfo.InstalledUICulture
  • Get or Set the actual language
    CultureInfo language = new CultureInfo("ta");
    Thread.CurrentThread.CurrentUICulture = language;
    AppResources.Culture = language;

Step 4: Implementation of Multi-Lingual

  • Open your designer file and add the resources as shown in below code snippet.
    <?xml version="1.0" encoding="utf-8"?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:resource="clr-namespace:MultilingualXFSample.Resources"
                 x:Class="MultilingualXFSample.MainPage">
            <Label Text="{x:Static resource:AppResources.WelcomeText}"
                   FontSize="Large"/>
    </ContentPage>
  • By default, the app will take the base resource file. By passing the language code will takes the language specific resource file and we can set the language as shown in below code snippet in runtime
    CultureInfo language = new CultureInfo("ta");
    Thread.CurrentThread.CurrentUICulture = language;
    AppResources.Culture = language;
    Application.Current.MainPage = new NavigationPage(new MainPage());

Output

Default - English Tamil French

Download Code

You can download the code from GitHub. If you have doubt, feel free to post comment. If you like this article and is useful to you, do like, share the article & star the repository on GitHub.

When considering how to build iOS and Android applications, many people think that the native languages, Objective-C, Swift, and Java, ...

Xamarin - Introduction Xamarin - Introduction

A blog about android developement

Cross Platform App Development


When considering how to build iOS and Android applications, many people think that the native languages, Objective-C, Swift, and Java, are the only choice. However, over the past few years, an entire new ecosystem of platforms for building mobile applications has emerged.

Xamarin is unique in this space by offering a single language – C#, class library, and runtime that works across all three mobile platforms of iOS, Android, and Windows Phone (Windows Phone’s native language is already C#), while still compiling native (non-interpreted) applications that are performant enough even for demanding games. 

Each of these platforms has a different feature set and each varies in its ability to write native applications – that is, applications that compile down to native code and that interop fluently with the underlying Java subsystem. For example, some platforms only allow apps to be built in HTML and JavaScript, whereas some are very low-level and only allow C/C++ code. Some platforms don’t even utilize the native control toolkit.  

In Androidmads, we will not cover the basics of Xamarin App development. But, we will cover the advanced concepts of Xamarin as well as we will assist you, if you find any help with Xamarin Basics. And also we will see about Flutter App development.