两种方式
1、在activity里面通过BroadcastReceiver Inter消息来监听耳机插拔
//实现类
private HeadsetReceiver mHeadsetReceiver ;
public class HeadsetReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_HEADSET_PLUG)) {
int state = intent.getIntExtra("state", 0);
if (intent.hasExtra("state")) {
1、在activity里面通过BroadcastReceiver Inter消息来监听耳机插拔
//实现类
private HeadsetReceiver mHeadsetReceiver ;
public class HeadsetReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_HEADSET_PLUG)) {
int state = intent.getIntExtra("state", 0);
if (intent.hasExtra("state")) {