How to start a service when the android Device is turned on?

前端 未结 1 1704
后悔当初
后悔当初 2020-12-29 15:26

How to start a service when the android Device is turned on and the OS run ?

1条回答
  •  情话喂你
    2020-12-29 15:53

    Add to AndroidManifest.xml:

    
    
    
    
      
          
              
          
    
    

    Create class AutoStart.java:

    public class AutoStart extends BroadcastReceiver
    {
    
        @Override
        public void onReceive(Context context, Intent intent) 
        {
            Intent startServiceIntent = new Intent(context, YourService.class);
            context.startService(startServiceIntent);       
        }
    
    }
    

    0 讨论(0)
提交回复
热议问题