rmtmckenzie / flutter_qr_mobile_vision

QR reader plugin using mobile vision API for Flutter.
MIT License
217 stars 186 forks source link

🐛 [PERMISSION DENY] App crashes when denying notifications permission on Android SDK 33 #207

Open aoancea opened 2 years ago

aoancea commented 2 years ago

App crashes when denying notifications permission on Android SDK 33

I've upgrade to latest flutter version 3.3.1 and firebase_messaging: 13.0.3

I'm also using the new way for request notification permission from flutter_local_notifications: 11.0.1

flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<
    AndroidFlutterLocalNotificationsPlugin>().requestPermission();

I'm placing below the error log

I/cgr.qrmv.QrMobVisPlugin( 9376): Permissions request denied.
W/cgr.qrmv.QrMobVisPlugin( 9376): Starting QR Mobile Vision failed
W/cgr.qrmv.QrMobVisPlugin( 9376): com.github.rmtmckenzie.qrmobilevision.QrReader$Exception: QR reader failed because noPermissions
W/cgr.qrmv.QrMobVisPlugin( 9376):   at com.github.rmtmckenzie.qrmobilevision.QrMobileVisionPlugin.onRequestPermissionsResult(QrMobileVisionPlugin.java:90)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onRequestPermissionsResult(FlutterEngineConnectionRegistry.java:777)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onRequestPermissionsResult(FlutterEngineConnectionRegistry.java:409)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onRequestPermissionsResult(FlutterActivityAndFragmentDelegate.java:757)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at io.flutter.embedding.android.FlutterActivity.onRequestPermissionsResult(FlutterActivity.java:748)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:8759)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.app.Activity.dispatchActivityResult(Activity.java:8617)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.app.ActivityThread.deliverResults(ActivityThread.java:5340)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.app.ActivityThread.handleSendResult(ActivityThread.java:5386)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2308)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.os.Handler.dispatchMessage(Handler.java:106)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.os.Looper.loopOnce(Looper.java:201)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.os.Looper.loop(Looper.java:288)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at android.app.ActivityThread.main(ActivityThread.java:7898)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at java.lang.reflect.Method.invoke(Native Method)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
W/cgr.qrmv.QrMobVisPlugin( 9376):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
D/AndroidRuntime( 9376): Shutting down VM
E/AndroidRuntime( 9376): FATAL EXCEPTION: main
E/AndroidRuntime( 9376): Process: com.fourgirlsforchange.d.bloodochallenge, PID: 9376
E/AndroidRuntime( 9376): java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=1, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.fourgirlsforchange.d.bloodochallenge/com.example.app_flutter.MainActivity}: java.lang.NullPointerException: Attempt to read from field 'io.flutter.plugin.common.MethodChannel$Result com.github.rmtmckenzie.qrmobilevision.QrMobileVisionPlugin$ReadingInstance.startResult' on a null object reference in method 'void com.github.rmtmckenzie.qrmobilevision.QrMobileVisionPlugin.startingFailed(java.lang.Throwable)'
E/AndroidRuntime( 9376):    at android.app.ActivityThread.deliverResults(ActivityThread.java:5347)
E/AndroidRuntime( 9376):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:5386)
E/AndroidRuntime( 9376):    at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
E/AndroidRuntime( 9376):    at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
E/AndroidRuntime( 9376):    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime( 9376):    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime( 9376):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2308)
E/AndroidRuntime( 9376):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 9376):    at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime( 9376):    at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime( 9376):    at android.app.ActivityThread.main(ActivityThread.java:7898)
E/AndroidRuntime( 9376):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 9376):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime( 9376):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
E/AndroidRuntime( 9376): Caused by: java.lang.NullPointerException: Attempt to read from field 'io.flutter.plugin.common.MethodChannel$Result com.github.rmtmckenzie.qrmobilevision.QrMobileVisionPlugin$ReadingInstance.startResult' on a null object reference in method 'void com.github.rmtmckenzie.qrmobilevision.QrMobileVisionPlugin.startingFailed(java.lang.Throwable)'
E/AndroidRuntime( 9376):    at com.github.rmtmckenzie.qrmobilevision.QrMobileVisionPlugin.startingFailed(QrMobileVisionPlugin.java:218)
E/AndroidRuntime( 9376):    at com.github.rmtmckenzie.qrmobilevision.QrMobileVisionPlugin.onRequestPermissionsResult(QrMobileVisionPlugin.java:90)
E/AndroidRuntime( 9376):    at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onRequestPermissionsResult(FlutterEngineConnectionRegistry.java:777)
E/AndroidRuntime( 9376):    at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onRequestPermissionsResult(FlutterEngineConnectionRegistry.java:409)
E/AndroidRuntime( 9376):    at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onRequestPermissionsResult(FlutterActivityAndFragmentDelegate.java:757)
E/AndroidRuntime( 9376):    at io.flutter.embedding.android.FlutterActivity.onRequestPermissionsResult(FlutterActivity.java:748)
E/AndroidRuntime( 9376):    at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:8759)
E/AndroidRuntime( 9376):    at android.app.Activity.dispatchActivityResult(Activity.java:8617)
E/AndroidRuntime( 9376):    at android.app.ActivityThread.deliverResults(ActivityThread.java:5340)
E/AndroidRuntime( 9376):    ... 13 more

If I remove the dependecy to qr_mobile_vision: 4.0.1, everything works fine If I add a dependency to qr_code_scanner: 1.0.1, everything works fine

aoancea commented 2 years ago

@rmtmckenzie any updates on this ?

giannuzzoexe commented 1 year ago

I have the same issue

matheuslns commented 1 month ago

I discovered the problem: the qr_mobile_vision package and flutter_local_notifications use the same code to request permissions, which is why it causes an error when used together.

The solution is to modify the REQUEST_PERMISSION field to a unique code.

Package: qr_mobile_vision File: QrMobileVisionPlugin.java

private static final int REQUEST_PERMISSION = 1;

Package: flutter_local_notifications File: FlutterLocalNotificationsPlugin.java

static final int NOTIFICATION_PERMISSION_REQUEST_CODE = 1;