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