Several lines of code can be used to start playing music (BOOT Startup Program)

Source: Internet
Author: User

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.

 

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.