Service with Broadcastreceiver for start-up Autorun

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.