BroadcastReceiver for ACTION_MEDIA_BUTTON not working

前端 未结 3 1305
轻奢々
轻奢々 2020-12-01 14:44

I am writing an Android application for version 4.0.3 (ICS) of the Android OS. The issue is that I am not getting the output from my Log.d() in the onReceive() method of the

3条回答
  •  春和景丽
    2020-12-01 15:00

    mediaButtonReceiver = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName());
    
    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    
    mAudioManager.registerMediaButtonEventReceiver(mediaButtonReceiver);
    

    This code will bind your headphone button to your app and your app only until you call:

    mAudioManager.unregisterMediaButtonEventReceiver(mediaButtonReceiver);
    

提交回复
热议问题