i'm trying to control (Play and Pause ) music from notification my code below works fine on all android version i think expect android 8.1.0 API 27.
BroadcastReceiver :
public class MyIntentService extends BroadcastReceiver {
public static final String RESUME_ACTION = "RESUME_ACTION";
public static final String STOP_ACTION = "STOP_ACTION";
public static int REQUEST_CODE_NOTIFICATION = 1212;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null) {
switch (intent.getAction()) {
case RESUME_ACTION:
MApplication.sBus.post(PlaybackEvent.PAUSE);
break;
case STOP_ACTION:
MApplication.sBus.post(PlaybackEvent.PLAY);
break;
}
}
}
}
<receiver
android:name=".MyIntentService"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="RESUME_ACTION" />
<action android:name="STOP_ACTION" />
</intent-filter>
</receiver>