The example in this article describes the Android implementation of the automatic start service or app. Share to everyone for your reference, specific as follows:
Step One: First create a broadcast receiver, refactor its abstract method OnReceive (context, Intent Intent), in which you start the service or app you want to start.
Import Android.content.BroadcastReceiver;
Import Android.content.Context;
Import android.content.Intent;
Import Android.util.Log;
public class Bootbroadcastreceiver extends Broadcastreceiver {
//overriding OnReceive method
@Override public
Void OnReceive (context, Intent Intent) {
//behind Xxx.class is the service to be started
Intent services = new Intent (context, Xxxclass);
Context.startservice (service);
LOG.V ("TAG", "power-on automatic service starts automatically ...");
Start the application with the package name Intent Intent = Getpackagemanager () for the application that needs to be started automatically
. Getlaunchintentforpackage (PackageName);
Context.startactivity (intent);
}
Step Two: Configure the XML file to receive this add Intent-filter configuration in Receiver
<receiver android:name= "Bootbroadcastreceiver" >
<intent-filter>
<action android:name= " Android.intent.action.BOOT_COMPLETED "></action>
<category android:name=" Android.intent.category.LAUNCHER "/>
</intent-filter>
</receiver>
Step Three: Add permissions
Copy Code code as follows:
<uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED"/>
For more information on Android-related content readers can view the site topics: "The activity of Android programming skills Summary", "Android Database Operating skills summary", "Android Development introduction and Advanced Course", "Android Resources operating Skills Summary , Android file Operation tips Summary, Android View tips Summary, and the Android control usage summary
I hope this article will help you with the Android program.