I need to detect the bluetooth HeadPhone device button click in my application. I followed many stackoverflow links, but doesn't seem to work for me.
Actual Working, When Headphone Button Clicked, Text apper in application "Button Pressed" or any other else
In this link I have tried, API 28 but its not Working Registering a headset button click with BroadcastReceiver in Android
No Error and No Output
public class RemoteControlReceiver extends BroadcastReceiver {
public RemoteControlReceiver(){
super();
}
@Override
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
Log.i ("TAG", intentAction.toString() + " happended");
if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
Log.i ("TAG", "no media button information");
return;
}
KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event == null) {
Log.i ("TAG", "no keypress");
return;
}
}
MainActivity
IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
RemoteControlReceiver r = new RemoteControlReceiver();
registerReceiver(r, filter);