Android is the way to start the service or app automatically at boot _android

Source: Internet
Author: User

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.

Related Article

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.