当前位置: 编程技术>移动开发
android FM播放时拔出耳机后FM APP自动close解决方法
来源: 互联网 发布时间:2014-10-17
本文导语: 1.修改FMRadioService.java 添加: 代码如下: 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.Proc...
1.修改FMRadioService.java
添加:
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;
}
}
};
2.修改onReceive 方法
在
switchAntennaAsync(mValueHeadSetPlug);
之后添加:
if(mValueHeadSetPlug == 1 && mIsPowerUp )
sHandler11.sendMessageDelayed(sHandler.obtainMessage(MSG_EXIT_FM, FMRadioService.this),(long)1000);
else
sHandler11.removeMessages(MSG_EXIT_FM);
添加:
代码如下:
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;
}
}
};
2.修改onReceive 方法
在
switchAntennaAsync(mValueHeadSetPlug);
之后添加:
代码如下:
if(mValueHeadSetPlug == 1 && mIsPowerUp )
sHandler11.sendMessageDelayed(sHandler.obtainMessage(MSG_EXIT_FM, FMRadioService.this),(long)1000);
else
sHandler11.removeMessages(MSG_EXIT_FM);