خرید بک لینک

Vote count: 0

I try to handle bluetooth - headset key pressing , but I have a trouble: My receiver does not recieve Intent.ACTION_MEDIA_BUTTON when I press this button. Manifest contains permission - bluetooth. Here s my receiver code:

<receiver android:name="com.mypackage.receivers.BluetoothReceiver">
            <intent-filter android:priority="2147483647">
                <action android:name="android.intent.action.MEDIA_BUTTON"/>
            </intent-filter>
        </receiver>


public class BluetoothReceiver extends BroadcastReceiver  {

    public BluetoothReceiver() {

    }


    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        if (action.equals(Intent.ACTION_MEDIA_BUTTON)) {
            ...
        }
        abortBroadcast();
    }
}

For handling key events I use such code:

ComponentName mediaButtonReceiver = new ComponentName(App.getAppContext(),BluetoothReceiver.class);
       mediaSession = new MediaSessionCompat(App.getAppContext(), "MY_TAG",
                mediaButtonReceiver, null);
        mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
                MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
        mediaSession.setCallback(new MediaSessionCompat.Callback() {
            @Override
            public boolean onMediaButtonEvent(Intent mediaButtonEvent) {
               Log.i("TAG","media button event");
                retu super.onMediaButtonEvent(mediaButtonEvent);
            }
        });
        mediaSession.setActive(true);

onMediaButtonEvent() and onReceive() does not invokes when I press headset button. Also I tried to use a deprecated methods

manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        mediaButtonReceiver = new ComponentName(App.getAppContext(), BluetoothReceiver.class);
        manager.registerMediaButtonEventReceiver(mediaButtonReceiver);

It also does not work. What Im doing wrong?And why intent does not received when I press headset button ?( i test code at the fiew different bt-headsets)

asked 40 secs ago

- - , .
.

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 21 تير 1395 ساعت: 19:16

صفحه بندی