耳机蓝牙(诺基亚)按钮recive呼叫Recive Android> 4.0

时间:2016-01-26 13:29:48

标签: java android android-intent bluetooth

我在stackoverflow中搜索我的问题的答案,我看到了很多信息,但我没有找到解决问题的方法。 我试着通过按钮诺基亚耳机蓝牙来调用recive。

在Manifest中我有:

 <receiver android:name=".ButtonBroadcastReceiver">
        <intent-filter android:priority="1000000000">
            <action android:name="android.intent.action.MEDIA_BUTTON" />
            <action android:name="android.media.VOLUME_CHANGED_ACTION" />
        </intent-filter>
    </receiver>

接下来我有课

public class ButtonBroadcastReceiver extends BroadcastReceiver {


    public ButtonBroadcastReceiver() {
        super();
    }
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.v("TTT", "KJEEEEEEEEEEEEEEEEEEEEEEEE");
        if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
            /* handle media button intent here by reading contents */
            /* of EXTRA_KEY_EVENT to know which key was pressed    */
        }
    }
}

在onCreate里面的活动我用

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

        mAudioManager.registerMediaButtonEventReceiver(mediaButtonReceiver);

当我使用+或 - 来升/降时它起作用! (在日志中我有我的消息)但是当我尝试单击按钮以重新呼叫时,呼叫日志是干净的。

1 个答案:

答案 0 :(得分:1)

我通过捕获按下PowerButton时触发的事件来解决它。在这种情况下,它是SCREEN_ON标志。在这里:capture hard-button events when phone is locked?