3. Installation for Maui - JimmyPun610/BarcodeScanner.Mobile GitHub Wiki
- Install package from nuget
Install Nuget package to Forms, Android and iOS project, you may need to specify the version since it is still in pre-release mode.
Install-Package BarcodeScanner.Mobile.Maui
Add the handles in MauiProgram.cs
usingBarcodeScanner.Mobile;
varbuilder=MauiApp.CreateBuilder();builder.UseMauiApp<App>().ConfigureFonts(fonts =>{fonts.AddFont("OpenSans-Regular.ttf","OpenSansRegular");fonts.AddFont("OpenSans-Semibold.ttf","OpenSansSemibold");}).ConfigureMauiHandlers(handlers =>{// Add the handlershandlers.AddBarcodeScannerHandler();});returnbuilder.Build();
Edit your maui.csproj
<PropertyGroup>
<!-- Choose either one, if you only want to deploy in any one. (Maui is still unstable, I am not sure if it is required... --><!-- Android Config -->
<TargetFrameworks>net6.0-android;</TargetFrameworks>
<!-- iOS Config --><!--<TargetFrameworks>net6.0-ios;</TargetFrameworks>-->
</PropertyGroup>
<!-- Setup iOS RuntimeIdentifier and Cpu target, support real device only -->
<PropertyGroupCondition="( '$(TargetFramework)' == 'net6.0-ios' )">
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
<PlatformTarget>arm64</PlatformTarget>
</PropertyGroup>
<!-- Have to include this package here otherwise build will be failed -->
<ItemGroupCondition="( '$(TargetFramework)' == 'net6.0-android' )">
<PackageReferenceInclude="Xamarin.Google.MLKit.BarcodeScanning"Version="116.1.2.5">
</PackageReference>
</ItemGroup>
- Android setup
Manifest.xml
<uses-permissionandroid:name="android.permission.VIBRATE" />
<uses-permissionandroid:name="android.permission.FLASHLIGHT" />
<uses-permissionandroid:name="android.permission.CAMERA" />
<!-- In case you need the features of Scan from Image, add below permissions -->
<application ...............>
........
<providerandroid:name="androidx.core.content.FileProvider"android:authorities="{your_app_id}.fileprovider"android:exported="false"android:grantUriPermissions="true">
<meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/file_paths"></meta-data>
</provider>
........
</application>
<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
In case you need the features of Scan from Image, add file_paths.xml with Build Action "AndroidResource" to Resources\xml (You may create "xml" folder if it is not exist)
<key>NSCameraUsageDescription</key>
<string>Require to use camera</string>
<!-- In case you need the features of Scan from Image, add below permissions -->
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to photos.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app needs access to the photo gallery.</string>