i am getting an issue in Bluetooth action event in Oreo

Multi tool use
Multi tool use


i am getting an issue in Bluetooth action event in Oreo



I can't getting any bluetooth action event in android o where below oreo its working fine getting all event like action_next,paused,play,previous etc. Here I register receiver in manifest and receiving event in that class but in oreo it's not working. Here I have implemented code is


bluetooth


android o



private static final int DOUBLE_CLICK_DELAY = 600;


private static long sLastClickTime = 0;

/**
* The constant delegate.
*/
public static Delegate delegate;

/**
* The interface Delegate.
*/
public interface Delegate {
/**
* On media button next.
*/
void onMediaButtonNext();

/**
* On media button previous.
*/
void onMediaButtonPrevious();

/**
* On media button play.
*/
void onMediaButtonPlay();

/**
* On media button pause.
*/
void onMediaButtonPause();


}

/**
* Process a media button key press.
*
* @param context A context to use.
* @param event The key press event.
* @return True if the event was handled and the broadcast should be aborted.
*/
public static boolean processKey(Context context, KeyEvent event) {

if (event == null)
return false;

int action = event.getAction();
String act = null;

switch (event.getKeyCode()) {

case KeyEvent.KEYCODE_MEDIA_NEXT:
if (action == KeyEvent.ACTION_DOWN) {
Log.d("Mediabutton", "Action next");
if (delegate != null)
delegate.onMediaButtonNext();
}
// act = PlaybackService.ACTION_NEXT_SONG_AUTOPLAY;
break;
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
if (action == KeyEvent.ACTION_DOWN) {
Log.d("Mediabutton", "Action prev");
if (delegate != null)
delegate.onMediaButtonPrevious();

}
// act = PlaybackService.ACTION_PREVIOUS_SONG_AUTOPLAY;
break;
case KeyEvent.KEYCODE_MEDIA_PLAY:
if (action == KeyEvent.ACTION_DOWN) {
if (delegate != null)
delegate.onMediaButtonPlay();
}
Log.d("Mediabutton", "Action play");
// act = PlaybackService.ACTION_PLAY;
break;
case KeyEvent.KEYCODE_MEDIA_PAUSE:
if (action == KeyEvent.ACTION_DOWN) {
if (delegate != null)
delegate.onMediaButtonPause();
Log.d("Mediabutton", "Action pause");
}

// act = PlaybackService.ACTION_PAUSE;
break;
default:
return false;
}

return true;
}

@Override
public void onInit(int status) {

}




/**
* The constant mLastClickTime.
*/
public static long mLastClickTime;

@Override
public void onReceive(Context context, Intent intent) {
Log.d("Mediabuttonrec", "onreceive");
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
if (SystemClock.elapsedRealtime() - mLastClickTime < 1000) {
return;
}
mLastClickTime = SystemClock.elapsedRealtime();
KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);

boolean handled = processKey(context, event);

}
}.



Any solution for that ?





If your app is in the foreground are you getting events? (with Oreo)
– Hed Shafran
Jul 3 at 6:22





no even my app is in forground then also not get any event
– Mehul Tank
Jul 3 at 6:24









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

g2m7DFEO8Wt4q,dCOQcc
6,d6XtUtxBmPTdQYLYvqG6w,Nx8Vjr

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications