如何确定Android中的设备启动事件 [英] How to determine Device startup event in android
问题描述
我想在我的android应用程序中保留一个日志,该日志将包含Device Started(启动)(设备启动)和Device Stop Times(设备停止时间).任何想法如何做到这一点?
I want to mantain a log in my android application , log will contain the Device Started (Bootup) and Device Stop Times. Any Idea how to do this ?
我必须在Bootup上启动我的应用程序,但是如何确定该应用程序是在Bootup上启动的?
I have to start my application on Bootup , But how to determine that application is started on Bootup ?
我已经搜索过,但找不到更好的解决方案.
I have searched but could not find a better solution.
推荐答案
使用 BroadCastReceiver
接收 BOOT_COMPLETED
广播.此广播在设备启动时引发
Use BroadCastReceiver
to receive BOOT_COMPLETED
broadcast. This broadcast is thrown in device startup
接收者会像
<receiver
android:name="ReceiverName"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
您将需要使用以下权限
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
现在在代码中编写一个 BroadCastReceiver
类,例如
now in code write a BroadCastReceiver
class like
public class ReceiverName extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// do startup tasks or start your luncher activity
}
}
这篇关于如何确定Android中的设备启动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!