HeadsetReceiver mReceiver = new HeadsetReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_HEADSET_PLUG);
registerReceiver(mReceiver, filter);
public class HeadsetReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
// do your stuff here
}
}
}
如果你已经完成了以上三步,仍然无法接收到ACTION_HEADSET_PLUG广播,那么可能是以下原因导致的:
希望这些解决方法能帮助你解决ACTION_HEADSET_PLUG广播接收问题。