码迷,mamicode.com
首页 > 移动开发 > 详细

debug debug Unable to add window android.view.View--permission denied for this window type

时间:2014-07-07 19:46:09      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   java   color   

bubuko.com,布布扣
 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                     @Override
21                     public void onClick(DialogInterface arg0, int arg1) {
22                         // TODO Auto-generated method stub
23                         
24                     }
25                 }).create();
26         builder.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
27         builder.show();
View Code

在调试代码中,报错误如下:

bubuko.com,布布扣
 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)
View Code

在报错中提示:
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" />

debug debug Unable to add window android.view.View--permission denied for this window type,布布扣,bubuko.com

debug debug Unable to add window android.view.View--permission denied for this window type

标签:android   style   blog   http   java   color   

原文地址:http://www.cnblogs.com/chuji1988/p/3813335.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!