在Android上,如何检测显示系统对话框(电源选项,最近的应用程序,电池电量低)? [英] On Android, how to detect a system dialog is displayed (power options, recent apps, low battery...)?

查看:346
本文介绍了在Android上,如何检测显示系统对话框(电源选项,最近的应用程序,电池电量低)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Stackoverflowers喜(我知道,听起来并不像它应该是...)

Hi Stackoverflowers (I know, that doesn't sound like it should...)

嗯,我认为这是几乎所有的问题:我想捕捉任何导致我活动的显示扯平部分隐藏,如:电源选项,最近应用程序托盘,电池电量低的通知,等等......,我有一个很难检测这些系统事件。

Well I think It's almost all in the question: I'd like to catch anything that causes the display of my Activity to get even partially hidden, e.g. power options, recent apps tray, low battery notification, etc... and I'm having a hard time to detect these system events.

我是pretty的肯定的onPause()当这样的事件发生时会被调用,但它似乎是错误的...抑或是我?

I was pretty sure onPause() would be called when such events happen, but it seems to be wrong... or is it me?

任何其他的想法?......我倒是preferably不是在每个系统广播动作勾独立,因为我想成为尽可能通用(和应对任何隐藏我的活动)。

Any other idea?... I'd preferably not hook on each system broadcast action individually, since I'd like to be as generic as possible (and react to ANYTHING that hides my Activity).

感谢任何投入!

推荐答案

在工作的一个信息亭风格的应用程序,我知道有些对话框来到前台,并且可以通过

On working on a kiosk style app I know that some Dialogs come to the foreground and can be detected by

    ActivityManager activityManager = ActivityManager)getBaseContext()
       .getSystemService(Activity.ACTIVITY_SERVICE);
    String className = amen.getRunningTasks(1).get(0).topActivity.getClassName();

有该一个例子是蓝牙结合对话框,带来了com.android.settings到前台。

An example for that is the bluetooth-binding dialog that brings the com.android.settings to the foreground.

一个反例是电源按钮对话框(关闭,重新启动等),不走到前台。

A counter-example is the power-button dialog (Turn off, Reboot etc) that does not come to the foreground.

请注意,您可以关闭系统对话框(即使是电源按钮对话框)与该广播:

Note that you can close system dialogs (even the power-button dialog) with this broadcast:

    Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        sendBroadcast(closeDialog);

不过,在大多数(全部更新?)设备,这个广播,甚至会关闭软键盘,所以它不是最好有经常将其作为用户届时将无法输入任何内容到一个文本字段中服务运行。

But on most (all newer?) devices this Broadcast will even close the software keyboard, so it is not advisable to have a service running that frequently sends it as the user will then be unable to enter anything into a text field.

请注意,这种行为将definetly满足你的应用状态为beeing恶意软件,从beeing刊登在谷歌发挥保持它。

Note that such behaviour will definetly gratify your app a status as beeing malware, keeping it from beeing published on google play.

这篇关于在Android上,如何检测显示系统对话框(电源选项,最近的应用程序,电池电量低)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆