JimmyPun610 / BarcodeScanner.Mobile

Barcode Scanner using GoogleVision API for Xamarin Form, Maui
MIT License
345 stars 101 forks source link

.Net 8 Maui Blazor Camera not openining only white screen is coming #212

Closed rajeshsws closed 11 months ago

rajeshsws commented 11 months ago

@JimmyPun610 My code was working fine in .NET 7 after converting to .NET 8, camera is not coming. After debugging i found this error.

[Camera2CameraImpl] {Camera@e772f28[id=0]} Cancelling scheduled re-open: androidx.camera.camera2.internal.Camera2CameraImpl$StateCallback$ScheduledReopen@38257a1 [Camera2CameraImpl] {Camera@e772f28[id=0]} Opening camera. [Camera2CameraImpl] {Camera@e772f28[id=0]} Transitioning camera internal state: REOPENING --> OPENING [CameraStateMachine] New public camera state CameraState{type=OPENING, error=null} from OPENING and null [UseCaseAttachState] All use case: [androidx.camera.core.Preview-68f3ec60-8011-42e7-8d23-537ef72376266181736, androidx.camera.core.ImageAnalysis-4335fd4e-fba8-4474-b350-79a70e9ed249146636903] for camera: 0 [CameraManager] Using legacy camera HAL. [Camera2CameraImpl] {Camera@e772f28[id=0]} Unable to open camera due to Lacking privileges to access camera service [Camera2CameraImpl] {Camera@e772f28[id=0]} Transitioning camera internal state: OPENING --> REOPENING [CameraStateMachine] New public camera state CameraState{type=OPENING, error=null} from OPENING and null [Camera2CameraImpl] Camera reopening attempted for 10000ms without success. [Camera2CameraImpl] {Camera@e772f28[id=0]} Transitioning camera internal state: REOPENING --> PENDING_OPEN

Permission is already given in menifest file

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />

Below is my xmal code <?xml version="1.0" encoding="utf-8" ?> <mct:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

         xmlns:mct="clr-namespace:CommunityToolkit.Maui.Views;assembly=CommunityToolkit.Maui"

        xmlns:GV="clr-namespace:BarcodeScanner.Mobile;assembly=BarcodeScanner.Mobile.Maui"

         x:Class="ProX.MauiPages.PopUpScanner">
<ScrollView >
    <VerticalStackLayout >

        <GV:CameraView VibrationOnDetected="True" 
                       WidthRequest="250" HeightRequest="350" 
                       HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" OnDetected="GoogleCamera_OnDetected"   TorchOn="False"  x:Name="GoogleCamera">

        </GV:CameraView>

        <Switch IsToggled="true"  VerticalOptions="Center"  HorizontalOptions="Center" x:Name="Switch" Toggled="Switch_Toggled" OnColor="Orange" ThumbColor="Green"/>
    </VerticalStackLayout>
</ScrollView>

</mct:Popup>

Code behind private void GoogleCamera_OnDetected(object sender, BarcodeScanner.Mobile.OnDetectedEventArg e) {

  List<BarcodeResult> obj = e.BarcodeResults;
      string result = string.Empty;
      for (int i = 0; i < obj.Count; i++)
      {
          result += obj[i].DisplayValue.ToString();
          break;
      }
      SecureStorage.Default.SetAsync("Camera", Switch.IsToggled.ToString());
      this.Close(result);
      GoogleCamera.IsScanning = false;

}

rajeshsws commented 11 months ago

Firebase.Core.resources/GoogleUtilitiesComponents.xcframework/ios-arm64/GoogleUtilitiesComponents.framework/GoogleUtilitiesComponents : warning MT7091: The framework C:\Users\shoky.nuget\packages\xamarin.firebase.ios.core\8.10.0.3\lib\net6.0-ios15.4\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64\GoogleUtilitiesComponents.framework is a framework of static libraries, and will not be copied to the app. 1>C:/Users/shoky/AppData/Local/XamarinBuildDownloadCache/MLKBarcode-1.6.0/Frameworks/MLKitBarcodeScanning.framework/MLKitBarcodeScanning : warning MT7091: The framework C:\Users\shoky\AppData\Local\XamarinBuildDownloadCache\MLKBarcode-1.6.0\Frameworks\MLKitBarcodeScanning.framework is a framework of static libraries, and will not be copied to the app. 1>C:/Users/shoky/AppData/Local/XamarinBuildDownloadCache/MLKMDD-3.0.0/Frameworks/MLKitMDD.framework/MLKitMDD : warning MT7091: The framework C:\Users\shoky\AppData\Local\XamarinBuildDownloadCache\MLKMDD-3.0.0\Frameworks\MLKitMDD.framework is a framework of static libraries, and will not be copied to the app. 1>C:/Users/shoky/AppData/Local/XamarinBuildDownloadCache/MLKVision-3.0.0/Frameworks/MLKitVision.framework/MLKitVision : warning MT7091: The framework C:\Users\shoky\AppData\Local\XamarinBuildDownloadCache\MLKVision-3.0.0\Frameworks\MLKitVision.framework is a framework of static libraries, and will not be copied to the app. 1>C:/Users/shoky/AppData/Local/XamarinBuildDownloadCache/MLImg-1.0.0beta2/Frameworks/MLImage.framework/MLImage : warning MT7091: The framework C:\Users\shoky\AppData\Local\XamarinBuildDownloadCache\MLImg-1.0.0beta2\Frameworks\MLImage.framework is a framework of static libraries, and will not be copied to the app. 1>C:/Users/shoky/AppData/Local/XamarinBuildDownloadCache/MLKCore-5.0.0/Frameworks/MLKitCommon.framework/MLKitCommon : warning MT7091: The framework C:\Users\shoky\AppData\Local\XamarinBuildDownloadCache\MLKCore-5.0.0\Frameworks\MLKitCommon.framework is a framework of static libraries, and will not be copied to the app. 1>C:/Users/shoky/AppData/Local/XamarinBuildDownloadCache/GAppM-8.9.1/GoogleAppMeasurement-8.9.1/Frameworks/GoogleAppMeasurement.xcframework/ios-arm64_armv7/GoogleAppMeasurement.framework/GoogleAppMeasurement : warning MT7091: The framework C:\Users\shoky\AppData\Local\XamarinBuildDownloadCache\GAppM-8.9.1\GoogleAppMeasurement-8.9.1\Frameworks\GoogleAppMeasurement.xcframework\ios-arm64_armv7\GoogleAppMeasurement.framework is a framework of static libraries, and will not be copied to the app. 1>C:/Users/shoky/AppData/Local/XamarinBuildDownloadCache/MLKBarcode-1.6.0/Frameworks/MLKitBarcodeScanning.framework/MLKitBarcodeScanning : warning MT7091: The framework C:\Users\shoky\AppData\Local\XamarinBuildDownloadCache\MLKBarcode-1.6.0\Frameworks\MLKitBarcodeScanning.framework is a framework of static libraries, and will not be copied to the app. 1>C:/Users/shoky/AppData/Local/XamarinBuildDownloadCache/MLKMDD-3.0.0/Frameworks/MLKitMDD.framework/MLKitMDD : warning MT7091: The framework C:\Users\shoky\AppData\Local\XamarinBuildDownloadCache\MLKMDD-3.0.0\Frameworks\MLKitMDD.framework is a framework of static libraries, and will not be copied to the app. 1>C:/Users/shoky/AppData/Local/XamarinBuildDownloadCache/MLKVision-3.0.0/Frameworks/MLKitVision.framework/MLKitVision : warning MT7091: The framework C:\Users\shoky\AppData\Local\XamarinBuildDownloadCache\MLKVision-3.0.0\Frameworks\MLKitVision.framework is a framework of static libraries, and will not be copied to the app. 1>C:/Users/shoky/AppData/Local/XamarinBuildDownloadCache/MLImg-1.0.0beta2/Frameworks/MLImage.framework/MLImage : warning MT7091: The framework C:\Users\shoky\AppData\Local\XamarinBuildDownloadCache\MLImg-1.0.0beta2\Frameworks\MLImage.framework is a framework of static libraries, and will not be copied to the app. 1>C:/Users/shoky/AppData/Local/XamarinBuildDownloadCache/MLKCore-5.0.0/Frameworks/MLKitCommon.framework/MLKitCommon : warning MT7091: The framework C:\Users\shoky\AppData\Local\XamarinBuildDownloadCache\MLKCore-5.0.0\Frameworks\MLKitCommon.framework is a framework of static libraries, and will not be copied to the app.

rajeshsws commented 11 months ago

[Camera2CameraImpl] {Camera@d7b3fa[id=0]} Unable to open camera due to validateClientPermissionsLocked:1167: Caller "com.companyname.testcam" (PID 10399, UID 7119) cannot open camera "0" without camera permission [Camera2CameraImpl] {Camera@d7b3fa[id=0]} Transitioning camera internal state: OPENING --> REOPENING [CameraStateMachine] New public camera state CameraState{type=OPENING, error=null} from OPENING and null [Camera2CameraImpl] Camera reopening attempted for 10000ms without success. [Camera2CameraImpl] {Camera@d7b3fa[id=0]} Transitioning camera internal state: REOPENING --> PENDING_OPEN

rajeshsws commented 11 months ago

My Problem is solved

rbev commented 10 months ago

My Problem is solved

How was your problem solved? It's generally useful to let others know what the fix is.

rajeshsws commented 10 months ago

Under platform folder, in android main activity, you need to give permission for camera in .net 8, public class MainActivity : MauiAppCompatActivity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState);

     Task<bool> allowed =  BarcodeScanner.Mobile.Methods.AskForRequiredPermission();

 }

}

Hope this will resolve your problem