In order for the service to run automatically with the application, you can let Broadcastreceiver listen to the intent of the action action_boot_completed constant. You can then start a specific service in the Broadcastreceiver.
Import Android.content.BroadcastReceiver;
Import Android.content.Context;
Import android.content.Intent;
Import Android.sax.StartElementListener;
public class Launchreceiver extends broadcastreceiver{
@Override
public void OnReceive (context context, Intent Intent) {
Intent tintent = new Intent (context, launchservice.class);
Start the specified service
Context.startservice (tintent);
}
}
The key to automating the operation is to have the Launchreceiver monitoring system boot-up broadcast, so you need to configure the Broadcastreceiver in the Androidmanifest.xml file with the following code:
<!--define a broadcastreceiver, and the monitoring system starts broadcasting---
<receiver android:name= ". Launchreceiver ">
<intent-filter >
<action android:name= "Android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
In addition, to allow the program to access the system boot event, you also need to add permissions to the application:
<!--grant the application access to the system boot events--
<uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED"/>
As for the application of the Launchservice, it can be a user-developed service, both monitoring the user calls the service, can also be listening to user text messages, block blacklist calls and other service,
Service with Broadcastreceiver for start-up Autorun