首页 > 代码库 > debug debug Unable to add window android.view.View--permission denied for this window type
debug debug Unable to add window android.view.View--permission denied for this window type
1 AlertDialog builder=new AlertDialog.Builder(context).setTitle("注意:") 2 .setIcon(R.drawable.dailog_icon) 3 .setMessage("MS0"+ReceiveNumber+"请求建立语音连接,是否同意?") 4 .setPositiveButton("同意", new DialogInterface.OnClickListener() { 5 6 @Override 7 public void onClick(DialogInterface arg0, int arg1) { 8 // TODO Auto-generated method stub 9 /*发送语音连接请求,同意接收*/10 System.out.println("进入语音连接请求中……………………");11 new Thread(new DataSend(CreateSignal.LinkReply(businessType))).start();/*发送连接请求同意信令,businessType业务类型*/12 new Thread(new DataSend(CreateSignal.AudioReceive())).start();/*发送音频接收操作命令*/13 Intent audioIntent=new Intent(context,PhoneInterface.class);14 audioIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);15 context.startActivity(audioIntent);16 }17 })18 .setNegativeButton("取消", new DialogInterface.OnClickListener() {19 20 @Override21 public void onClick(DialogInterface arg0, int arg1) {22 // TODO Auto-generated method stub23 24 }25 }).create();26 builder.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);27 builder.show();
在调试代码中,报错误如下:
1 04-05 15:17:15.279: E/AndroidRuntime(1575): FATAL EXCEPTION: main 2 04-05 15:17:15.279: E/AndroidRuntime(1575): android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@4103e4c0 -- permission denied for this window type 3 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewRootImpl.setView(ViewRootImpl.java:537) 4 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:301) 5 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215) 6 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140) 7 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.Window$LocalWindowManager.addView(Window.java:537) 8 04-05 15:17:15.279: E/AndroidRuntime(1575): at com.compal.android.framework.elastic.Elasticview$PrimeviewTouchListener.onTouch(Elasticview.java:96) 9 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.View.dispatchTouchEvent(View.java:5536)10 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1951)11 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1712)12 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)13 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1684)14 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)15 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1684)16 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)17 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1684)18 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)19 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1684)20 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)21 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1684)22 04-05 15:17:15.279: E/AndroidRuntime(1575): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1912)23 04-05 15:17:15.279: E/AndroidRuntime(1575): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1371)24 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.app.Activity.dispatchTouchEvent(Activity.java:2364)25 04-05 15:17:15.279: E/AndroidRuntime(1575): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1860)26 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.View.dispatchPointerEvent(View.java:5721)27 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2890)28 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)29 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)30 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)31 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.os.Handler.dispatchMessage(Handler.java:99)32 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.os.Looper.loop(Looper.java:137)33 04-05 15:17:15.279: E/AndroidRuntime(1575): at android.app.ActivityThread.main(ActivityThread.java:4424)34 04-05 15:17:15.279: E/AndroidRuntime(1575): at java.lang.reflect.Method.invokeNative(Native Method)35 04-05 15:17:15.279: E/AndroidRuntime(1575): at java.lang.reflect.Method.invoke(Method.java:511)36 04-05 15:17:15.279: E/AndroidRuntime(1575): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)37 04-05 15:17:15.279: E/AndroidRuntime(1575): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)38 04-05 15:17:15.279: E/AndroidRuntime(1575): at dalvik.system.NativeStart.main(Native Method)
在报错中提示:
Unable to add window android.view.ViewRootImpl$W@4103e4c0 -- permission denied for this window type
原因是:
发现在使用WindowManager.LayoutParams.TYPE_SYSTEM_ALERT涉及到window type权限问题。
修改代码如下:
在Mainfest.xml中添加window 权限:
<!-- 显示系统窗口权限 -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<!-- 在 屏幕最顶部显示addview-->
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。