Android boot up

Source: Internet
Author: User

use Android Studio to help us create a broadcast, click on the package name-->new--> Broadcastreceiver

It is automatically generated in the manifest file.

We add the action of the boot broadcast

<receiverAndroid:name=". Bootreceiver "android:enabled= "true"android:exported= "true">     <Intent-filter>          <ActionAndroid:name= "Android.intent.action.BOOT_COMPLETED"/>     </Intent-filter></receiver>

Plus the power-on Start permission

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

Modify the broadcast OnReceive method, let it pop up after the notification bar, convenient for us to observe

@Override Public voidOnReceive (Context context, Intent Intent) {notification.builder Builder=NewNotification.builder (context); Builder.setticker ("Notice of winning"); Builder.setautocancel (true); Builder.setcontenttitle ("Congratulations on your winning."); Builder.setcontenttext ("Your number is drawn by my company, winning 1 million, please contact: 139999");        Builder.setsmallicon (R.mipmap.ic_launcher); Notification Notification=Builder.build (); Notificationmanager Manager=(Notificationmanager) Context.getsystemservice (Context.notification_service); Manager.notify (1, notification); }

This is done, and most of us are letting it start a service.

Android boot up

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.