cordova-plugin-background-mode
cordova-plugin-background-mode copied to clipboard
I did my own fork to fix moveToBackground on Android
The way it is written it goes to the home screen. I wanted to go back to whatever the previous foreground app was. Took hours but I found it. I recommend whomever is maintaining this plugin to adopt this code instead.
private void moveToBackground() { Activity app = getApp(); app.moveTaskToBack(true); }
I also had to fix a bug in recent Android releases. for pendingintents you need to have a FLAG_MUTABLE or the opposite. So I had to edit ForeGroundService.java adding | PendingIntet.FLAG_MUTABLE as shown below on line 225.
if (intent != null && settings.optBoolean("resume")) { intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity( context, NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);