客戶要求FM播放時拔出耳機後,FM APP出現“拔出耳機,Fm停止"的提示框,然後自動close
修改FMRadioService.java
1.添加如下import,以便能顯示toast
////AAAAA add start
import android.widget.Toast;
////AAAAA add end
public class FMRadioService extends Service implements FMRecorder.OnRecorderStateChangedListener {
2.在下面函數onBind()前添加
//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 intent) {
return mBinder;
}
3.修改onReceive 方法,這樣子就可以顯示toast以及關閉Fm app了
在 switchAntennaAsync(mValueHeadSetPlug);
之後添加:
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.在alps\mediatek\packages\apps\FMRadio\res\values\strings.xml中添加
<string name="toast_plugin_headphone_before_FM">The FM will close because you have been plug out
the headphone</string>