提问人:Abdulbasit Sakhi 提问时间:11/12/2023 更新时间:11/12/2023 访问量:17
传递结果失败 ResultInfo{request=0, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }}
Failure delivering result ResultInfo{request=0, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }}
问:
我正在尝试获得READ_CONTACTS,WRITE_CONTACTS许可。 每当我第一次构建应用程序时,它都会询问我权限,当我允许它时,应用程序会突然关闭。 这是我的代码
@override
void initState() {
super.initState();
_askPermissions('');
}
Future<void> _askPermissions(String routeName) async {
PermissionStatus permission = await Permission.contacts.status;
if (permission == PermissionStatus.granted) {
getContacts();
} else {
_handleInvalidPermissions(permission);
}
}
void _handleInvalidPermissions(PermissionStatus permissionStatus) {
if (permissionStatus == PermissionStatus.denied) {
final snackBar = SnackBar(content: Text('Access denied'));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
} else if (permissionStatus == PermissionStatus.permanentlyDenied) {
final snackBar =
SnackBar(content: Text('Data not available on device'));
}
}
这是我在Android显示器中收到的错误消息
Shutting down VM
E/AndroidRuntime( 4831): FATAL EXCEPTION: main
E/AndroidRuntime( 4831): Process: com.sakhi.dailler, PID: 4831
E/AndroidRuntime( 4831): java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=0, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.sakhi.dailler/com.sakhi.dailler.MainActivity}: java.lang.NullPointerException
E/AndroidRuntime( 4831): at android.app.ActivityThread.deliverResults(ActivityThread.java:4386)
E/AndroidRuntime( 4831): at android.app.ActivityThread.handleSendResult(ActivityThread.java:4428)
E/AndroidRuntime( 4831): at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
E/AndroidRuntime( 4831): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
E/AndroidRuntime( 4831): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
E/AndroidRuntime( 4831): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1814)
E/AndroidRuntime( 4831): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 4831): at android.os.Looper.loop(Looper.java:280)
E/AndroidRuntime( 4831): at android.app.ActivityThread.main(ActivityThread.java:6710)
E/AndroidRuntime( 4831): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 4831): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime( 4831): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/AndroidRuntime( 4831): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 4831): at com.yanisalfian.flutterphonedirectcaller.FlutterPhoneDirectCallerHandler.onRequestPermissionsResult(FlutterPhoneDirectCallerPlugin.kt:85)
E/AndroidRuntime( 4831): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onRequestPermissionsResult(FlutterEngineConnectionRegistry.java:785)
E/AndroidRuntime( 4831): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onRequestPermissionsResult(FlutterEngineConnectionRegistry.java:413)
E/AndroidRuntime( 4831): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onRequestPermissionsResult(FlutterActivityAndFragmentDelegate.java:816)
E/AndroidRuntime( 4831): at io.flutter.embedding.android.FlutterActivity.onRequestPermissionsResult(FlutterActivity.java:952)
E/AndroidRuntime( 4831): at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7608)
E/AndroidRuntime( 4831): at android.app.Activity.dispatchActivityResult(Activity.java:7458)
E/AndroidRuntime( 4831): at android.app.ActivityThread.deliverResults(ActivityThread.java:4379)
E/AndroidRuntime( 4831): ... 11 more
I/Process ( 4831): Sending signal. PID: 4831 SIG: 9
我已经在AndoridManifest.xml中将权限定义为清单元素的直接子项
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
为什么权限对话框没有显示?
为什么我在回调方法中得到空权限和grantResults数组?
答: 暂无答案
评论