After the headset is removed during android FM playback, the fm app displays a prompt box Indicating & quot; the headset is unplugged, And the Fm stops & quot ;.

Source: Internet
Author: User

After the customer asks the FM to unplug the headset during playback, the fm app displays a prompt box Indicating "unplug the headset and stop the Fm", and then automatically closes

Modify FMRadioService. java
1. Add the following import to display the toast
/// AAAAA add start
Import android. widget. Toast;
/// AAAAA add end
Public class FMRadioService extends Service implements FMRecorder. OnRecorderStateChangedListener {
2. Before the onBind () function, add
// AAAAA add start
Public static final int MSG_EXIT_FM = 1234;
Private Handler sHandler11 = new Handler (){
@ Override
Public void handleMessage (Message msg ){
FMRadioLogUtils. d (TAG, "sHandler11 =" + msg. what );
Switch (msg. what ){
Android. OS. Process. killProcess (android. OS. Process. myPid ());
Private Toast mToast = null;
Private void showToast (CharSequence text ){
If (null = mToast ){
MToast = Toast. makeText (mContext, text, Toast. LENGTH_SHORT );
MToast. setText (text );
MToast. show ();
LogUtils. v (TAG, "FMRadioActivity. showToast: toast =" + text );
// AAAAA add end
@ Override
Public IBinder onBind (Intent intent ){
Return mBinder;
3. Modify the onReceive method to display the toast and disable the Fm app.
In switchAntennaAsync (mValueHeadSetPlug );
Then add:
If (mValueHeadSetPlug = 1 & mIsPowerUp)
ShowToast (getString (R. string. toast_plugin_headphone_before_FM ));
SHandler11.sendMessageDelayed (sHandler. obtainMessage (MSG_EXIT_FM, FMRadioService. this), (long)
1000 );
MFmServiceHandler. removeCallbacksAndMessages (null );
StopFMFocusLoss (AudioManager. AUDIOFOCUS_LOSS );
SHandler11.removeMessages (MSG_EXIT_FM );
4. In alps \ mediatek \ packages \ apps \ FMRadio \ res \ values \ strings. xml, add
<String name = "toast_plugin_headphone_before_FM"> The FM will close because you have been plug out
The headphone </string>

Related Article

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: 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.