哪个手机关闭的时间戳记?

Jit*_*r M 3 android android-alarms

对于android设备,

是否有办法找出设备在什么时间(或时间戳记)关闭?

waq*_*lam 5

我不认为对此有任何预定义的支持。但是,使用您的自定义逻辑很容易做到这一点。所有您需要做的就是定义一个BroadcastReceiver监听intent的android.intent.action.ACTION_SHUTDOWN。收到意图后,只需将当前内容保存DateSharedPreferencesSQLite或您想要的任何位置。稍后,手机将启动,读取保存的值以了解手机关机的估计时间。例如:

接收方代码:

public class ShutdownReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //save the date here
    }
}
Run Code Online (Sandbox Code Playgroud)

并在AndroidManifest.xml中

<receiver android:name=".ShutdownReceiver">
  <intent-filter>
    <action android:name="android.intent.action.ACTION_SHUTDOWN" />
  </intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)