This time, the style is sharp and the source code is directly used:
1. Here is a broadcastreceiver that enables media playback.
Package COM. william. broadcastreceivertest; <br/> Import android. content. broadcastreceiver; <br/> Import android. content. context; <br/> Import android. content. intent; <br/> Import android. media. mediaplayer; <br/> public class myreceiver extends broadcastreceiver {<br/> @ override <br/> Public void onreceive (context arg0, intent arg1) {</P> <p> mediaplayer. create (arg0, R. raw. wake_up_call ). start (); <br/>}< br/>}
2. In the registration file, broadcastreceiver sets the intent attribute of the android. Intent. Action. boot_completed type action on the receiving system.
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <manifest xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> package = "com. william. broadcastreceivertest "<br/> Android: versioncode =" 1 "<br/> Android: versionname =" 1.0 "> <br/> <application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name"> <br/> <Cycler Android: name = "myreceiver"> <br/> <intent-filter> <br/> <action Android: Name = "android. intent. action. boot_completed "/> <br/> </intent-filter> <br/> </javaser> <br/> </Application> <br/> <uses-SDK Android: minsdkversion = "8"/> <br/> <uses-Permission Android: Name = "android. permission. receive_boot_completed "/> <br/> </manifest>
Pay attention to the particularity of the following two sentences. If you want to understand it, you can go to Google for a hundred times:
<Intent-filter> <br/> <action Android: Name = "android. intent. action. boot_completed "/> <br/> </intent-filter> <br/> <uses-Permission Android: Name =" android. permission. receive_boot_completed "/>
You only need to perform these operations to play a song at startup. At the same time, we can also use this principle to enable the startup of our application. Please explore for details.