The FM radio needs to be plugged into the headset as an antenna and automatically exits when the headset is unplugged
1. First add a hint string
Mediatek/packages/apps/fmradio/res/values/strings.xml
<!--tchip ZJ Add below--><string name= "toast_plugin_headphone_before_fm" >the FM would close because you had B Een plug out the headphone</string><string name= "Toast_fm_enter_airplane_mode" >the FM would close because you has been entered the airplane mode</string>
2.Modify Fmradioservice
Mediatek/packages/apps/fmradio/src/com/mediatek/fmradio/fmradioservice.java
---a/mediatek/packages/apps/fmradio/src/com/mediatek/fmradio/fmradioservice.java+++ b/mediatek/packages/apps/ fmradio/src/com/mediatek/fmradio/fmradioservice.java@@ -227,6 +227,34 @@ public class Fmradioservice extends Service Implements Fmrecorder.onrecorderstat//ADD This lock the EXITFM () while stoprecording () private Object Mstoprecor Dinglock = new Object (); +++//{@TChip ZJ Add start++ public static final int msg_exit_fm = 1234;+ private Handler sHandler11 = new Handler () {+ @ override+ public void Handlemessage (Message msg) {+ LOGUTILS.D (TAG, "sHandler11 =" + msg.what); + Switch (msg.wha T) {+ 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.make Text (mcontext, text, toast.length_short), +}+ Mtoast.settext (text), + mtoast.show (); + LOGUTILS.V (T AG, "FmradioactIvity.showToast:toast = "+ text") +};++//tchip ZJ Add [email protected]}+ @Override public IBinder Onbi nd (Intent Intent) {logutils.d (TAG, "Fmradioservice.onbind:" + Intent); @@ -319,6 +347,21 @@ -319,6 class Fmradios Ervice extends Service implements FMRECORDER.ONRECORDERSTAT//switch antenna should not impact audio FOCU s Status Mvalueheadsetplug = (Intent.getintextra ("state",-1) = = headset_plug_in)? 0:1; Switchantennaasync (mvalueheadsetplug) +//{@TChip ZJ Add start++if (mvalueheadsetplug = = 1 && mispowerup) +{+ Sho Wtoast (getString (R.STRING.TOAST_PLUGIN_HEADPHONE_BEFORE_FM)); + shandler11.sendmessagedelayed ( Shandler11.obtainmessage (MSG_EXIT_FM, Fmradioservice.this), (long) +1000); + Mfmservicehandler.removecallbacksandmessages (null); +stopfmfocusloss (Audiomanager.audiofocus_loss); +}+ else+ Shandler11.removemessages (MSG_EXIT_FM); ++//tchip ZJ Add end+ if (short_anntenna_support) { Boolean isswitch = (Switchantenna (mvalueheadsetplug) = = 0)? True:false; LOGUTILS.D (TAG, "Onreceive.switch anntenna:iswitch:" + isswitch); @@ -380,7 +423,27 @@ -380,7 class Fmradioservice extends Service implements Fmrecorder.onrecorderstat logutils.d (TAG, "Setfmviabtcontroller (false) succeeded!!"); Musingfmviabtcontroller = false; Enablefmaudio (True);-} */else {+} */++//{@TChip ZJ Add start++else if (intent.action_airplane_mode_ Changed.equals (Action)) {+ Boolean isairplanemode = Intent.getbooleanextra ("state", false); + if (Isairplanemode) { + LOGUTILS.D (TAG, ">>>action_airplane_mode_changed"), + if (Mispowerup) {+ sh Owtoast (getString (R.string.toast_fm_enter_airplane_mode)); + shandler11.sendmessagedelayed (SHANDLER11.OBTA Inmessage (MSG_EXIT_FM, Fmradioservice.this), (long) + Mfmservicehandler.remOvecallbacksandmessages (null); + Stopfmfocusloss (audiomanager.audiofocus_loss); +}+ } +}++//tchip ZJ Add END @}+++else {logutils.w (TAG, "error:undefined action."); } logutils.d (TAG, "<<< fmradioservice.onreceive"); @@ -1557,6 +1620,7 @@ -1557,6 class Fmradioservice E Xtends Service implements Fmrecorder.onrecorderstat filter.addaction (Intent.action_shutdown); Filter.addaction (intent.action_screen_on); Filter.addaction (Intent.action_screen_off); +filter.addaction (intent.action_airplane_mode_changed);//TChip ZJ ADD Filter.addaction (Action_shutdown_ipo); Filter.addaction (Action_pre_shutdown);
Android automatically exits the FM radio app when you turn on airplane mode and unplug the headset