mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-14 19:44:53 +00:00
Allow app from being excluded from recent list
This commit is contained in:
parent
c2fedef6d2
commit
18fc64fddb
@ -113,6 +113,13 @@ Override the back button on Android to go to background instead of closing the a
|
||||
cordova.plugins.backgroundMode.overrideBackButton();
|
||||
```
|
||||
|
||||
### Recent task list
|
||||
Exclude the app from the recent task list works on Android 5.0+.
|
||||
|
||||
```javascript
|
||||
cordova.plugins.backgroundMode.excludeFromTaskList();
|
||||
```
|
||||
|
||||
### Notification
|
||||
To indicate that the app is executing tasks in background and being paused would disrupt the user, the plug-in has to create a notification while in background - like a download progress bar.
|
||||
|
||||
|
@ -102,6 +102,7 @@
|
||||
<preference name="windows-target-version" value="UAP" />
|
||||
<preference name="uap-target-min-version" value="10.0.14393.0" />
|
||||
<preference name="Windows.Universal-MinVersion" value="10.0.14393.0" />
|
||||
<preference name="Windows.Universal" value="10.0.14393.0" />
|
||||
</config-file>
|
||||
|
||||
<resource-file src="appbeep.wma" target="appbeep.wma" />
|
||||
|
@ -22,10 +22,12 @@
|
||||
package de.appplant.cordova.plugin.background;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.view.View;
|
||||
|
||||
@ -36,6 +38,7 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
public class BackgroundMode extends CordovaPlugin {
|
||||
|
||||
@ -114,6 +117,10 @@ public class BackgroundMode extends CordovaPlugin {
|
||||
moveToForeground();
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase("tasklist")) {
|
||||
excludeFromTaskList();
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase("enable")) {
|
||||
enableMode();
|
||||
}
|
||||
@ -333,6 +340,33 @@ public class BackgroundMode extends CordovaPlugin {
|
||||
thread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude the app from the recent tasks list.
|
||||
*/
|
||||
private void excludeFromTaskList() {
|
||||
ActivityManager am = (ActivityManager) cordova.getActivity()
|
||||
.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
|
||||
if (am == null || Build.VERSION.SDK_INT < 21)
|
||||
return;
|
||||
|
||||
try {
|
||||
Method getAppTasks = am.getClass().getMethod("getAppTasks");
|
||||
List tasks = (List) getAppTasks.invoke(am);
|
||||
|
||||
if (tasks == null || tasks.isEmpty())
|
||||
return;
|
||||
|
||||
ActivityManager.AppTask task = (ActivityManager.AppTask) tasks.get(0);
|
||||
Method setExcludeFromRecents = task.getClass()
|
||||
.getMethod("setExcludeFromRecents", boolean.class);
|
||||
|
||||
setExcludeFromRecents.invoke(task, true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire vent with some parameters inside the web view.
|
||||
*
|
||||
|
@ -158,6 +158,17 @@ exports.moveToForeground = function () {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Exclude the app from the recent tasks list (Android only).
|
||||
*
|
||||
* @return [ Void ]
|
||||
*/
|
||||
exports.excludeFromTaskList = function () {
|
||||
if (this._isAndroid) {
|
||||
cordova.exec(null, null, 'BackgroundMode', 'tasklist', []);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Override the back button on Android to go to background
|
||||
* instead of closing the app.
|
||||
|
Loading…
Reference in New Issue
Block a user