How to determine Device startup event in android

前端 未结 2 1599
萌比男神i
萌比男神i 2021-01-22 14:15

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 ?

I have to start my appl

2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-22 14:50

    You can use BroadcastReceiver component for this purpose. Using this you can detect various events of your device like booting.

    To Detect Booting process you need to give permission in AndroidManifest.xml as below,

    
    

    Then you need to create a BrodacastReceiver which will handle this,

    In the onReceive() method the corresponding BroadcastReceiver would then start the event,

    public class MyReceiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            Intent service = new Intent(context, WordService.class);
            context.startService(service);
        }
    }
    

提交回复
热议问题