Error代码:
new AlertDialog.Builder(getActivity().getApplicationContext()) .setTitle("No phone access permission") ****** .show();
Error描述,使用AlertDialog.Builder报错:
2018-11-13 11:48:32.264 1062-1062/air.app E/AndroidRuntime: FATAL EXCEPTION: main Process: air.app, PID: 1062 java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=65636, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {*.activity.BaseActivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application at android.app.ActivityThread.deliverResults(ActivityThread.java:4089) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4132) at android.app.ActivityThread.-wrap20(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1533) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application at android.view.ViewRootImpl.setView(ViewRootImpl.java:683) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93) at android.app.Dialog.show(Dialog.java:322) at android.app.AlertDialog$Builder.show(AlertDialog.java:1112) at android.support.v4.app.FragmentActivity.onRequestPermissionsResult(FragmentActivity.java:911) at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7084) at android.app.Activity.dispatchActivityResult(Activity.java:6936) at android.app.ActivityThread.deliverResults(ActivityThread.java:4085) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4132) at android.app.ActivityThread.-wrap20(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1533) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
解决方案:需要当前activity的context
new AlertDialog.Builder(ConfirmFragment.this.getContext()) .setTitle("No phone access permission") ****** .show();
作者:Susie 出处:https://www.cnblogs.com/zwting/p/9952752.html 欢迎转载,但还请尊重劳动果实,保留此段声明并注明原文链接。
|