Customer requirements
After the headset is pulled out during FM playback, FM appAppears"Unplug the headset and FM stops"Prompt box, And thenAutomatic close
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. Add it before the onbind () function
// 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 ){
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>