How to determine Device startup event in android

前端 未结 2 1596
萌比男神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条回答
  •  失恋的感觉
    2021-01-22 15:11

    Use BroadCastReceiver to receive BOOT_COMPLETED broadcast. This broadcast is thrown in device startup

    The receiver will be like

        
            
                
                
            
        
    

    You will need to use the following persmission

    
    

    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
        }
    }
    

提交回复
热议问题