Android boot broadcast and android Broadcast

Source: Internet
Author: User

Android boot broadcast and android Broadcast

Sometimes we often need a program to start up and run. At this time, we need to listen to the system boot broadcast, and then start our program.

Not to mention the Code directly:

 

Public class BootReceiver extends BroadcastReceiver {@ Overridepublic void onReceive (Context context, Intent intent) {LogUtil. I ("BootReceiver", "BootReceiver is onReceive"); // TestService. startService (context); // start the service here }}

 

The colleague needs to add the permission to receive the boot broadcast in AndroidManifest. xml.

<Uses-permission android: name = "android. permission. RECEIVE_BOOT_COMPLETED"/>

Register the broadcast in AndroidManifest. xml.

<Cycler android: name = "com. test. bootreceiver. bootReceiver "> <intent-filter> <action android: name =" android. intent. action. BOOT_COMPLETED "/> </intent-filter> </Cycler>

 

So the success is ~~~~~~~~~

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.