android4.0开机自启

1.目的:在某些安卓 设备开机自启(广告屏等)

2.权限设置


    

3.新建BootReceiver

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class BootReceiver extends BroadcastReceiver{
   static final String ACTION="android.intent.action.BOOT_COMPLETED";

   @Override
   public void onReceive(Context context, Intent intent) {
      
      if(intent.getAction().equals(ACTION))
      {
         Intent mainIntent=new Intent(context, MainActivity.class);
         mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(mainIntent);
      }
   }
   
}

4.在配置文件中配置页面BootReceiver


    
        
            

            
        
    

    
        
            
            
        
    

5.此时就可以开机自启app了

 

 

你可能感兴趣的:(Android)