Broadcast receiver priority priority not working

I am using an application using the ACTION_MEDIA_BUTTON handler, but it seems like it is always intercepted by MX Player or Apollo, and I don't get Intent

I tried both 1000 and 2147483647 priority set in the tag, and right after the constructor using setPriority

Applications work if there is no MX Player or Apollo

I also tried using the headset interceptor application from Google Play, I tried to block events in MX Player using the Autostarts application - nothing helps

in onCreate:

IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON); filter.addAction(Intent.ACTION_HEADSET_PLUG); filter.setPriority(1000); registerReceiver(receiver, filter); 

in the receiver

 @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) { // NEVER REACHES HERE WHEN MX PLAYER PRESENT. WORKS IF NOT 

in manifest

 <receiver android:name="BCreceiver" android:enabled="true"> <intent-filter android:priority="1000"> <action android:name="android.intent.action.MEDIA_BUTTON" /> <action android:name="android.intent.action.HEADSET_PLUG" /> </intent-filter> </receiver> 
+6
source share
4 answers

To capture the headset button, you must also register the receiver in the media in onCreate in Activity.

 AudioManager manager = (AudioManager) getSystemService(AUDIO_SERVICE); manager.registerMediaButtonEventReceiver(new ComponentName(getPackageName(), BCreceiver.class.getName())); 
+1
source

Refer to the line " The value must be greater than -1000 and less than 1000. " from the link below, the highest priority - 999 is not 1000.

http://developer.android.com/guide/topics/manifest/intent-filter-element.html

+9
source

Although this is a small old question, I am adding my results so that it helps new visitors.

To get Intent.ACTION_MEDIA_BUTTON, a broadcast registration assignment from the code is not required. The documentation says that the intent should be recorded in the manifest. Failed to get it to work from registering from code.

Use registerMediaButtonEventReceiver

Priority is set in the android:priority="<int value>" manifest android:priority="<int value>" . I used 2147483647 and was even able to override the player. I read that winamp uses the highest priority.

Hope this helps.

+2
source

First of all, you should not register the recipient in the code if it has already been mentioned in the manifest. Then the recipient name is not valid, it must be either the full name of the class or the abbreviation that will be added to the name of the application package. If BCreceiver is in the main package, the attribute value must be ".BCreceiver" . The last mention that you should not change the priority, there is no such thing as a broadcast capture in Android (as far as I know), so all BroadcastReceivers who subscribe to an action will receive a broadcast when it starts. Try these fixes and update your question.

+1
source

Source: https://habr.com/ru/post/953607/


All Articles