編輯:關於Android編程
FM收音機需要插入耳機作為天線,拔出耳機時要自動退出
1.首先添加提示字符串
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
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);
微信名字用了一段時間就想換一個,換個新鮮,微信名字怎麼改?微信名字如何加表情?下面我們就一起來瞧一瞧吧!微信名字怎麼改1.首先在手機上面登錄到自己的微信賬號
Android開發中的ProguardProguard是Android開發時經常會用到的一個工具,在Android SDK中已經集成了一個免費的Proguard版本,位於
本節引言: 上一節,我們學習了Xfermode兩個已經過世(過時)的兒子:AvoidXfermode, PixelXorXfermode, 雖然說有點用,但是
一加手機與錘子手機一直以來備受關注,近日陸續傳出一加2與錘子2的消息,而且兩者都選在7月28日同一天舉行手機發布會,是不是覺得很有趣?那麼,一加手機2和錘子