I use react-native-music-control, but I am sure that this is not particularly important for the solution. Just in case, the link https://www.npmjs.com/package/react-native-music-control. There was a task to create a button to close the application via a notification with a modal request window for the user to receive a sub-notification to close. For the simplicity of the solution, since there is no need to use the "next" button in the notification, I decided to use it as the basis for the solution. When you click on it, an event is triggered, which I process with this code in MusicControlReceiver.java:
public void onReceive(Context context, Intent intent) {
if(MusicControlNotification.MEDIA_BUTTON.equals(action) ||
Intent.ACTION_MEDIA_BUTTON.equals(action)) {
if(!intent.hasExtra(Intent.EXTRA_KEY_EVENT)) return;
if(!checkApp(intent)) return;
Intent openApp = context.getPackageManager().getLaunchIntentForPackage(packageName);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, openApp, 0);
KeyEvent ke = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (ke.getKeyCode() == 87) {
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, openApp, 0);
try {
pendingIntent.send();
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
}
// To close the notification bar:
Intent closeDialogs = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
context.sendBroadcast(closeDialogs);
module.session.getController().dispatchMediaButtonEvent(ke);
}
}
Everything works fine, my app comes to the foreground, closes the notification bar. In react native, I get an event and process it. But the problem is that if the device is locked, then when you click on the close button in the notification, the unlock window does not appear, as it would be with builder.setContentIntent(PendingIntent.getActivity(context, 0, openApp, 0));. But at the same time, everything you need in the background works out everything. How do I get this screen unlock mode to open?
Пробовал:
Intent openApp = context.getPackageManager().getLaunchIntentForPackage(packageName);
openApp.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(openApp);
I've been trying to get it to open for two weeks now, I've studied a lot of code, but nothing makes the unlock mode open. In android development for two weeks :) Maybe there is something in react native to handle the received event. I can't find anything in the solution there either.