Android automatically exits the FM Radio application when the flight mode is enabled and the headset is pulled out.
The FM radio needs to be inserted into the headset as an antenna, and automatically exits when the headset is pulled out.
1. First add the prompt string
Mediatek/packages/apps/FMRadio/res/values/strings. xml
The FM will close because you have been plug out the headphone
The FM will close because you have been entered the airplane mode
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 mStopRecordingLock = 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.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);+ };++// TChip ZJ Add END@}+ @Override public IBinder onBind(Intent intent) { LogUtils.d(TAG, "FMRadioService.onBind: " + intent);@@ -319,6 +347,21 @@ public class FMRadioService extends Service implements FMRecorder.OnRecorderStat // switch antenna should not impact audio focus status mValueHeadSetPlug = (intent.getIntExtra("state", -1) == HEADSET_PLUG_IN) ? 0 : 1; switchAntennaAsync(mValueHeadSetPlug);+//{@TChip ZJ Add START++if(mValueHeadSetPlug == 1 && mIsPowerUp )+{+ showToast(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 @@ public 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) {+ showToast(getString(R.string.toast_fm_enter_airplane_mode));+ sHandler11.sendMessageDelayed(sHandler11.obtainMessage(MSG_EXIT_FM, FMRadioService.this),(long)1000);+ 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 @@ public class FMRadioService extends 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);