2015年3月31日 星期二

[Android] How to load my APP automatically after system booting up

In order to start the program automatically after system booting up, we need to:

Assume that MainActivity is the start up Activity.
We need to add a new class extended from BroadcastReceiver to accept the broadcasted messages.
 public class BootUpReceiverClass extends BroadcastReceiver {
     @Override
     public void onReceive(Context context, Intent intent) {      
         Intent i = new Intent(context, MainActivity.class);  
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);          
         }
    }

Then, we need to add a permission in AndroidManifest.xml.
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

After that, we can a receiver tag within <application> </application>

   
       
       
      
    

沒有留言:

張貼留言