Android, how to determine if a reboot occurred?

前端 未结 4 1725
慢半拍i
慢半拍i 2021-01-14 09:33

How would I programmatically determine when an android device has rebooted (whether on its own, or user initiated) ?

4条回答
  •  轮回少年
    2021-01-14 10:13

    This snippet starts an Application automatically after the android-os booted up.

    in AndroidManifest.xml (application-part):

    // You must hold the RECEIVE_BOOT_COMPLETED permission in order to receive this broadcast. 
    
    
            
                    
                    
            
    
    [..]
    
    [..]
    

    In Java Class

     public class BootUpReceiver extends BroadcastReceiver{
    
                @Override
                public void onReceive(Context context, Intent intent) {
                        Intent i = new Intent(context, MyActivity.class);  
                        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(i);  
                }
    
    }
    

提交回复
热议问题