Justin-roy / Zebra-Rfid-Sdk-Plugin

Flutter Native SDK Plugin
Other
10 stars 6 forks source link

Error permission bluetooh with android 12 or higher #3

Closed orlando-gimo closed 1 year ago

orlando-gimo commented 1 year ago

hi , I have downloaded your project and I have tested with the ZEBRA RFID base Model RFD8500 it works only in debug for android 12 or higher, when compiling in release throws error java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource, permissions were added in androidmanifest,xml

 <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"/>
 <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation"/>
 <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
 <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

please, can you help me

Justin-roy commented 1 year ago

Add this permission into your android xml file under manifest.

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

orlando-gimo commented 1 year ago

hi, I have added all the bluetooth permissions in the manifest in profile, for release:

`<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.zebra_rfid_sdk_plugin_example">

 <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"/>
 <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation"/>
 <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
 <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

`

But I keep getting the error and the app closes, this only happens with android 12 or higher.

E/AndroidRuntime(12469): FATAL EXCEPTION: AsyncTask #1 E/AndroidRuntime(12469): Process: com.example.zebra_rfid_sdk_plugin_example, PID: 12469 E/AndroidRuntime(12469): java.lang.RuntimeException: An error occurred while executing doInBackground() E/AndroidRuntime(12469): at android.os.AsyncTask$4.done(AsyncTask.java:415) E/AndroidRuntime(12469): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:381) E/AndroidRuntime(12469): at java.util.concurrent.FutureTask.setException(FutureTask.java:250) E/AndroidRuntime(12469): at java.util.concurrent.FutureTask.run(FutureTask.java:269) E/AndroidRuntime(12469): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) E/AndroidRuntime(12469): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137) E/AndroidRuntime(12469): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637) E/AndroidRuntime(12469): at java.lang.Thread.run(Thread.java:1012) E/AndroidRuntime(12469): Caused by: java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource { uid = 10168, packageName = com.example.zebra_rfid_sdk_plugin_example, attributionTag = null, token = android.os.BinderProxy@c6bcae3, next = null }: AdapterService getBondedDevices E/AndroidRuntime(12469): at com.android.bluetooth.Utils.checkPermissionForDataDelivery(Utils.java:482) E/AndroidRuntime(12469): at com.android.bluetooth.Utils.checkConnectPermissionForDataDelivery(Utils.java:514) E/AndroidRuntime(12469): at com.android.bluetooth.btservice.AdapterService$AdapterServiceBinder.getBondedDevices(AdapterService.java:2122) E/AndroidRuntime(12469): at com.android.bluetooth.btservice.AdapterService$AdapterServiceBinder.getBondedDevices(AdapterService.java:2114) E/AndroidRuntime(12469): at android.bluetooth.IBluetooth$Stub.onTransact(IBluetooth.java:642) E/AndroidRuntime(12469): at android.os.Binder.execTransactInternal(Binder.java:1285) E/AndroidRuntime(12469): at android.os.Binder.execTransact(Binder.java:1244) W/FlutterActivityAndFragmentDelegate(12587): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.

Justin-roy commented 1 year ago

Currently I have no Zebra Device. But I have tested on Physical Device (i.e- android 12 device). It's working fine. (release mode)

This is my xml file permissions.

`

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH" />`
orlando-gimo commented 1 year ago

Dear, I have applied the permissions that you indicated, but the problems still continue in release, I am testing on a xaomi redmi note 9 pro and with a Pixel 4 XL emulator both with android 12 and with bluetooh activated, when bluetooh is deactivated it does not There are problems, I attach the error in release and the manifest in profile.

Manifest in release `<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.zebra_rfid_sdk_plugin_example">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />

`

manifest in debug

`

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />`

image with the permissions requested in release

image release

image that requests in debug with the permissions that we configure

image in debug

`flutter run --release Using hardware rendering with device sdk gphone64 x86 64. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering". Launching lib\main.dart on sdk gphone64 x86 64 in release mode... WARNING: [Processor] Library 'C:\Users\OrlandoAlfaro\source\Zebra-Rfid-Sdk-Plugin-main\example\android\RFIDAPI3Library\RFIDAPI3Library.aar' contains references to both AndroidX and old support library. This seems like the library is partially migrated. Jetifier will try to rewrite the library anyway. Example of androidX reference: 'androidx/core/content/ContextCompat' Example of support library reference: 'android/support/annotation/RequiresApi' Note: C:\Users\OrlandoAlfaro\source\Zebra-Rfid-Sdk-Plugin-main\android\src\main\java\com\example\zebra_rfid_sdk_plugin\RFIDHandler.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: C:\Users\OrlandoAlfaro\source\Zebra-Rfid-Sdk-Plugin-main\android\src\main\java\com\example\zebra_rfid_sdk_plugin\RFIDHandler.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Running Gradle task 'assembleRelease'... 68,6s √ Built build\app\outputs\flutter-apk\app-release.apk (8.6MB). Installing build\app\outputs\flutter-apk\app-release.apk... 745ms

Flutter run key commands. h List all available interactive commands. c Clear the screen q Quit (terminate the application on the device). E/AndroidRuntime(15077): FATAL EXCEPTION: AsyncTask #1 E/AndroidRuntime(15077): Process: com.example.zebra_rfid_sdk_plugin_example, PID: 15077 E/AndroidRuntime(15077): java.lang.RuntimeException: An error occurred while executing doInBackground() E/AndroidRuntime(15077): at android.os.AsyncTask$4.done(AsyncTask.java:415) E/AndroidRuntime(15077): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:381) E/AndroidRuntime(15077): at java.util.concurrent.FutureTask.setException(FutureTask.java:250) E/AndroidRuntime(15077): at java.util.concurrent.FutureTask.run(FutureTask.java:269) E/AndroidRuntime(15077): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) E/AndroidRuntime(15077): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137) E/AndroidRuntime(15077): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637) E/AndroidRuntime(15077): at java.lang.Thread.run(Thread.java:1012) E/AndroidRuntime(15077): Caused by: java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource { uid = 10171, packageName = com.example.zebra_rfid_sdk_plugin_example, attributionTag = null, token = android.os.BinderProxy@2600eb2, next = null }: AdapterService getBondedDevices E/AndroidRuntime(15077): at com.android.bluetooth.Utils.checkPermissionForDataDelivery(Utils.java:482) E/AndroidRuntime(15077): at com.android.bluetooth.Utils.checkConnectPermissionForDataDelivery(Utils.java:514) E/AndroidRuntime(15077): at com.android.bluetooth.btservice.AdapterService$AdapterServiceBinder.getBondedDevices(AdapterService.java:2122) E/AndroidRuntime(15077): at com.android.bluetooth.btservice.AdapterService$AdapterServiceBinder.getBondedDevices(AdapterService.java:2114) E/AndroidRuntime(15077): at android.bluetooth.IBluetooth$Stub.onTransact(IBluetooth.java:642) E/AndroidRuntime(15077): at android.os.Binder.execTransactInternal(Binder.java:1285) E/AndroidRuntime(15077): at android.os.Binder.execTransact(Binder.java:1244)`

thanks for your help.

regards.