我的问题是从服务的锁定屏幕上显示警报对话框.手机处于解锁状态时,显示效果很好.实际上,如果电话处于锁定状态,它将仅解锁电话,并且警报对话框将出现在锁定后面.这是我的代码:
Service.java:
public static voID popupDialog(String sender , String msg){ final String sendername = sender; final String message = msg; Handler h = new Handler(context.getMainLooper()); h.post(new Runnable() { @OverrIDe public voID run() { KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEyguard_SERVICE); if (km.inKeyguardRestrictedinputMode()) { lockFlag = true; Log.d ("---popup","lock"); powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); km = (KeyguardManager) context.getSystemService(Context.KEyguard_SERVICE); mkeyguardlock = km.newkeyguardlock("com.example.myapplication"); mkeyguardlock.disableKeyguard(); wl = powerManager.newWakeLock(PowerManager.FulL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "com.example.myapplication"); wl.acquire(); } else { Log.d ("---popup","unlock"); } final VIEw vIEw = VIEw.inflate(context.getApplicationContext(),R.layout.popup, null); final AlertDialog.Builder builder1 = new AlertDialog.Builder(context) .setCancelable(true) .setVIEw(vIEw); final ImageVIEw ImageVIEw1 = (ImageVIEw) vIEw.findVIEwByID(R.ID.ImageVIEw1); final TextVIEw TextVIEw1 = (TextVIEw) vIEw.findVIEwByID(R.ID.TextVIEw1); final TextVIEw TextVIEwSender = (TextVIEw) vIEw.findVIEwByID(R.ID.TextVIEwSender); TextVIEwSender.setText (sendername+":"); final TextVIEw TextVIEw2 = (TextVIEw) vIEw.findVIEwByID(R.ID.TextVIEw2); TextVIEw2.setText (message); final EditText EditText1 = (EditText) vIEw.findVIEwByID(R.ID.EditText1); final Imagebutton Imagebutton1 = (Imagebutton) vIEw.findVIEwByID(R.ID.Imagebutton1); Imagebutton1.setonClickListener( new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { /*do some task*/ } } }); AlertDialog alertDialog = builder1.create(); alertDialog.getwindow().setType(WindowManager.LayoutParams.TYPE_SYstem_ALERT); alertDialog.requestwindowFeature(Window.FEATURE_NO_Title); alertDialog.show(); } });}
我只想显示锁定时的警报对话框.
编辑:我使用AndroID Lolipop,并读取this link后,我使用TYPE_SYstem_OVERLAY而不是TYPE_SYstem_ALERT.在这种情况下,我无法在EditText上输入内容,甚至无法关闭对话框.
解决方法:
将类型更改为TYPE_SYstem_ERROR
更改
alertDialog.getwindow().setType(WindowManager.LayoutParams.TYPE_SYstem_ALERT);
至
alertDialog.getwindow().setType(WindowManager.LayoutParams.TYPE_SYstem_ERROR);
更新:
TYPE_SYstem_ALERT-窗口类型:系统窗口,例如低电量警报.这些窗口始终位于应用程序窗口的顶部.在多用户系统中,仅在拥有用户的窗口上显示.
常数:2003(0x000007d3)
TYPE_SYstem_ERROR-窗口类型:内部系统错误窗口,在所有可能的窗口顶部.在多用户系统中,仅在拥有用户的窗口上显示.
常量值:2010(0x000007da)
更多信息是here
总结以上是内存溢出为你收集整理的手机锁定时,Android-从服务显示警报对话框全部内容,希望文章能够帮你解决手机锁定时,Android-从服务显示警报对话框所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)