1Alertdialog builder=NewAlertdialog.builder (context). Settitle ("Note:")2 . SetIcon (R.drawable.dailog_icon)3. Setmessage ("MS0" +receivenumber+ "request to establish a voice connection, do you agree?") ")4. Setpositivebutton ("Consent",NewDialoginterface.onclicklistener () {5 6 @Override7 Public voidOnClick (Dialoginterface arg0,intarg1) {8 //TODO auto-generated Method Stub9 /*Send Voice connection request, agree to receive*/TenSystem.out.println ("Enter the Voice connection request .............")); One NewThread (NewDatasend (Createsignal.linkreply (Businesstype)). Start ();/*Send connection request consent signaling, Businesstype business type*/ A NewThread (NewDatasend (Createsignal.audioreceive ())). Start ();/*send an audio receive Operation command*/ -Intent audiointent=NewIntent (Context,phoneinterface.class); - audiointent.addflags (intent.flag_activity_new_task); the context.startactivity (audiointent); - } - }) -. Setnegativebutton ("Cancel",NewDialoginterface.onclicklistener () { + - @Override + Public voidOnClick (Dialoginterface arg0,intarg1) { A //TODO auto-generated Method Stub at - } - }). Create (); - Builder.getwindow (). SetType (WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); -Builder.show ();
View Code
In the debug code, the report error is as follows:
104-05 15:17:15.279:e/androidruntime (1575): FATAL exception:main204-05 15:17:15.279:e/androidruntime (1575): android.view.windowmanager$badtokenexception:unable to add window [email Protected]--Permission denied for Thiswindow Type304-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewRootImpl.setView (viewrootimpl.java:537)404-05 15:17:15.279:e/androidruntime (1575): at Android.view.WindowManagerImpl.addView (windowmanagerimpl.java:301)504-05 15:17:15.279:e/androidruntime (1575): at Android.view.WindowManagerImpl.addView (windowmanagerimpl.java:215)604-05 15:17:15.279:e/androidruntime (1575): at Android.view.windowmanagerimpl$compatmodewrapper.addview ( windowmanagerimpl.java:140)704-05 15:17:15.279:e/androidruntime (1575): at Android.view.window$localwindowmanager.addview (Window.java:537)804-05 15:17:15.279:e/androidruntime (1575): at com.compal.android.framework.elastic.elasticview$ Primeviewtouchlistener.ontouch (elasticview.java:96)904-05 15:17:15.279:e/androidruntime (1575): at Android.view.View.dispatchTouchEvent (view.java:5536)Ten04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewGroup.dispatchTransformedTouchEvent (Viewgroup.java : 1951) One04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewGroup.dispatchTouchEvent (viewgroup.java:1712) A04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewGroup.dispatchTransformedTouchEvent (Viewgroup.java : 1957) -04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewGroup.dispatchTouchEvent (viewgroup.java:1684) -04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewGroup.dispatchTransformedTouchEvent (Viewgroup.java : 1957) the04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewGroup.dispatchTouchEvent (viewgroup.java:1684) -04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewGroup.dispatchTransformedTouchEvent (Viewgroup.java : 1957) -04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewGroup.dispatchTouchEvent (viewgroup.java:1684) -04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewGroup.dispatchTransformedTouchEvent (Viewgroup.java : 1957) +04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewGroup.dispatchTouchEvent (viewgroup.java:1684) -04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewGroup.dispatchTransformedTouchEvent (Viewgroup.java : 1957) +04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewGroup.dispatchTouchEvent (viewgroup.java:1684) A04-05 15:17:15.279:e/androidruntime (1575): at com.android.internal.policy.impl.phonewindow$ Decorview.superdispatchtouchevent (phonewindow.java:1912) at04-05 15:17:15.279:e/androidruntime (1575): at Com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent (phonewindow.java:1371) -04-05 15:17:15.279:e/androidruntime (1575): at Android.app.Activity.dispatchTouchEvent (activity.java:2364) -04-05 15:17:15.279:e/androidruntime (1575): at com.android.internal.policy.impl.phonewindow$ Decorview.dispatchtouchevent (phonewindow.java:1860) -04-05 15:17:15.279:e/androidruntime (1575): at Android.view.View.dispatchPointerEvent (view.java:5721) -04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewRootImpl.deliverPointerEvent (Viewrootimpl.java : 2890) -04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewRootImpl.handleMessage (viewrootimpl.java:2466) in04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewRootImpl.processInputEvents (viewrootimpl.java:845) -04-05 15:17:15.279:e/androidruntime (1575): at Android.view.ViewRootImpl.handleMessage (viewrootimpl.java:2475) to04-05 15:17:15.279:e/androidruntime (1575): at Android.os.Handler.dispatchMessage (handler.java:99) +04-05 15:17:15.279:e/androidruntime (1575): at Android.os.Looper.loop (looper.java:137) -04-05 15:17:15.279:e/androidruntime (1575): at Android.app.ActivityThread.main (activitythread.java:4424) the04-05 15:17:15.279:e/androidruntime (1575): At Java.lang.reflect.Method.invokeNative (Native Method) *04-05 15:17:15.279:e/androidruntime (1575): at Java.lang.reflect.Method.invoke (method.java:511) $04-05 15:17:15.279:e/androidruntime (1575): at Com.android.internal.os.zygoteinit$methodandargscaller.run ( zygoteinit.java:784)Panax Notoginseng04-05 15:17:15.279:e/androidruntime (1575): at Com.android.internal.os.ZygoteInit.main (zygoteinit.java:551) -04-05 15:17:15.279:e/androidruntime (1575): at Dalvik.system.NativeStart.main (Native Method)
View Code
In the error message:
Unable to add window [e-mail protected]--Permission denied for this window type
The reasons are:
found that the use of WindowManager.LayoutParams.TYPE_SYSTEM_ALERT involves window TYPE permission issues.
Modify the code as follows:
To add window permissions in Mainfest.xml:
<!--display the system window permissions-->
<uses-permission android:name= "android.permission.SYSTEM_ALERT_ Window "/>
<!--display Addview--> at the top of the screen;
<uses-permission android:name=" Android.permission.SYSTEM_OVERLAY_WINDOW "/>