如何检测Android手机正在被关闭?

时间:2014-02-18 11:50:59

标签: android power-off

我想在用户关闭Android手机的瞬间做一些事情。我的应用程序如何以编程方式检测到它?

3 个答案:

答案 0 :(得分:6)

http://developer.android.com/reference/android/content/Intent.html#ACTION_SHUTDOWN`

<receiver android:name=".ShutdownReceiver">
    <intent-filter>
        <action android:name="android.intent.action.ACTION_SHUTDOWN" />
        <action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
    </intent-filter>
</receiver>

答案 1 :(得分:1)

这可以让您深入了解您正在使用的操作系统,而不是开发可在任何设备上运行的应用程序,因为您还没有为他们制作操作系统。

只需拉出一个Android分支,根据您的意愿自定义它,并在清单中删除过滤器,不允许您这样做的权限,或者添加自己的权限。现在,如果我谈的更深入,你必须使用电池。

但是如果你只是想触发关闭电源的话,那就简单了。

添加您的清单:

<receiver android:name=".ShutdownReceiver"> 
<intent-filter> 
    <action android:name="android.intent.action.ACTION_SHUTDOWN" /> 
    <action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
</intent-filter> </receiver>

现在行动关闭广播接收器将适合您。

http://developer.android.com/reference/android/content/Intent.html#ACTION_SHUTDOWN

答案 2 :(得分:0)

相关问题