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 ){
Case MSG_EXIT_FM:
Android. OS. Process. killProcess (android. OS. Process. myPid ());
Break;
}
}
};
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 );
}
Else
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>