Reputation: 489
I search answer to my problem inside stackoverflow and I seen a lot of information but I have not found a solution to my problem. I try to recive button nokia headset bluetooth to call recive.
In Manifest I have:
<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>
Next I have class
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 */
}
}
}
And in activity inside onCreate I use
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
ComponentName mediaButtonReceiver = new ComponentName(getPackageName(), ButtonBroadcastReceiver.class.getName());
mAudioManager.registerMediaButtonEventReceiver(mediaButtonReceiver);
When I use + or - to volue up/down it works! (in log i have my message) but when I try to click button to recive call log is clean.
Upvotes: 1
Views: 153
Reputation: 2348
I solved it by catching the event that is triggered when the PowerButton gets pressed. In this case it was the SCREEN_ON-flag. here: capture hard-button events when phone is locked?
Upvotes: 1