当前位置:主页 > 移动开发 > Android代码 >

android FM播放时拔出耳机后FM APP自动close解决方法

时间:2020-11-15 14:16:11 | 栏目:Android代码 | 点击:

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);

您可能感兴趣的文章:

相关文章