Android Application boot on boot

Source: Internet
Author: User

There are situations that require Android programs to boot, that is, after the phone is powered up immediately after the corresponding Android program.

The way to do this is to accept the corresponding broadcast when the phone is powered on, and to accept the broadcast in the Android program.

  1th Step: Build a custom broadcastreceiver class.

1  PackageCom.example.autostart;2 3 ImportAndroid.content.BroadcastReceiver;4 ImportAndroid.content.Context;5 Importandroid.content.Intent;6 ImportAndroid.widget.Toast;7 8  Public classBootupreceiverextendsBroadcastreceiver {9 Ten @Override One      Public voidOnReceive (Context context, Intent Intent) { AToast.maketext (Context, "App started", Toast.length_long). Show (); -         //---Start the main activity of our app--- -          theIntent i =NewIntent (context, mainactivity.class); - i.addflags (intent.flag_activity_new_task); - context.startactivity (i); -     } +}

2nd Step: Modify the Androidmanifest.xml file.

  Add the right to receive a power-on broadcast.

1 <uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED"/>

  Registers the custom Broadcastreceiver class.

1 <receiver android:name= ". Bootupreceiver ">2 <intent-filter>3 <action android:name=" Android.intent.action.BOOT _completed "/>45 <category android:name=" Android.intent.category.DEFAULT "/>  </intent-filter></receiver>

This was basically done, and I was able to experiment on the computer's AVD. But on my phone on the boot has no effect, I also set the corresponding permissions in the mobile butler, but it is not successful. After I put the phone on the security software Uninstall, the program has been successful since the start, I analyzed the installation of the mobile phone butler after receiving the boot broadcast, the broadcast ended.

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.