mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-21 23:04:53 +00:00
Avoid reflections
This commit is contained in:
parent
974d6c4e2a
commit
2801364ed8
@ -21,8 +21,10 @@
|
|||||||
|
|
||||||
package de.appplant.cordova.plugin.background;
|
package de.appplant.cordova.plugin.background;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
|
import android.app.ActivityManager.AppTask;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -148,6 +150,7 @@ class BackgroundExt {
|
|||||||
/**
|
/**
|
||||||
* Exclude the app from the recent tasks list.
|
* Exclude the app from the recent tasks list.
|
||||||
*/
|
*/
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
private void excludeFromTaskList() {
|
private void excludeFromTaskList() {
|
||||||
ActivityManager am = (ActivityManager) getActivity()
|
ActivityManager am = (ActivityManager) getActivity()
|
||||||
.getSystemService(Context.ACTIVITY_SERVICE);
|
.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
@ -155,21 +158,12 @@ class BackgroundExt {
|
|||||||
if (am == null || Build.VERSION.SDK_INT < 21)
|
if (am == null || Build.VERSION.SDK_INT < 21)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
List<AppTask> tasks = am.getAppTasks();
|
||||||
Method getAppTasks = am.getClass().getMethod("getAppTasks");
|
|
||||||
List tasks = (List) getAppTasks.invoke(am);
|
|
||||||
|
|
||||||
if (tasks == null || tasks.isEmpty())
|
if (tasks == null || tasks.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ActivityManager.AppTask task = (ActivityManager.AppTask) tasks.get(0);
|
tasks.get(0).setExcludeFromRecents(true);
|
||||||
Method setExcludeFromRecents = task.getClass()
|
|
||||||
.getMethod("setExcludeFromRecents", boolean.class);
|
|
||||||
|
|
||||||
setExcludeFromRecents.invoke(task, true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user