After the headset is removed during Android FM playback, the FM app displays a prompt box "unplug the headset and stop the FM", and then automatically closes
Source: Internet
Author: User
Customer requirements
After the headset is pulled out during FM playback, The FM app displays a prompt box Indicating "unplug the headset and stop the FM", and then automatically close
Modify fmradioservice. Java1. Add the following import to display the toast
/// AAAAA add start
Import Android. widget. Toast;
/// AAAAA add endpublic 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. xmlAdd
<String name = "toast_plugin_headphone_before_fm"> the FM will close because you have been plug outthe headphone </string>
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.