mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2025-12-16 19:33:23 +00:00
Compare commits
1 Commits
master
...
kerr/add-e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6000adfa15 |
@@ -1,9 +1,4 @@
|
|||||||
## ChangeLog
|
## ChangeLog
|
||||||
|
|
||||||
#### Version 0.8.0
|
|
||||||
- Set PendingIntent mutability (fixes #45)
|
|
||||||
- Depend on cordova-androidx-build to automatically work with AndroidX
|
|
||||||
|
|
||||||
#### Version 0.7.3 (not yet released)
|
#### Version 0.7.3 (not yet released)
|
||||||
- Check if screen is off on Android
|
- Check if screen is off on Android
|
||||||
- Wake-up device on Android
|
- Wake-up device on Android
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cordova-plugin-background-mode",
|
"name": "cordova-plugin-background-mode",
|
||||||
"version": "0.8.0",
|
"version": "0.7.3",
|
||||||
"description": "Prevent apps from going to sleep in background.",
|
"description": "Prevent apps from going to sleep in background.",
|
||||||
"cordova": {
|
"cordova": {
|
||||||
"id": "cordova-plugin-background-mode",
|
"id": "cordova-plugin-background-mode",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
id="cordova-plugin-background-mode"
|
id="cordova-plugin-background-mode"
|
||||||
version="0.8.0">
|
version="0.7.3">
|
||||||
|
|
||||||
<name>BackgroundMode</name>
|
<name>BackgroundMode</name>
|
||||||
|
|
||||||
@@ -93,8 +93,7 @@
|
|||||||
src="src/android/ForegroundService.java"
|
src="src/android/ForegroundService.java"
|
||||||
target-dir="src/de/appplant/cordova/plugin/background" />
|
target-dir="src/de/appplant/cordova/plugin/background" />
|
||||||
|
|
||||||
<framework src="androidx.core:core:1.0.0" />
|
<framework src="com.android.support:support-compat:27.1.1" />
|
||||||
<dependency id="cordova-androidx-build" />
|
|
||||||
<resource-file src="src/android/res/drawable/power.xml" target="res/drawable/power.xml" />
|
<resource-file src="src/android/res/drawable/power.xml" target="res/drawable/power.xml" />
|
||||||
<resource-file src="src/android/res/drawable-hdpi/power.png" target="res/drawable-hdpi/power.png" />
|
<resource-file src="src/android/res/drawable-hdpi/power.png" target="res/drawable-hdpi/power.png" />
|
||||||
<resource-file src="src/android/res/drawable-mdpi/power.png" target="res/drawable-mdpi/power.png" />
|
<resource-file src="src/android/res/drawable-mdpi/power.png" target="res/drawable-mdpi/power.png" />
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ public class BackgroundModeExt extends CordovaPlugin {
|
|||||||
case "webview":
|
case "webview":
|
||||||
disableWebViewOptimizations();
|
disableWebViewOptimizations();
|
||||||
break;
|
break;
|
||||||
|
case "enableWebview":
|
||||||
|
enableWebViewOptimizations();
|
||||||
|
break;
|
||||||
case "appstart":
|
case "appstart":
|
||||||
openAppStart(args.opt(0));
|
openAppStart(args.opt(0));
|
||||||
break;
|
break;
|
||||||
@@ -196,6 +199,31 @@ public class BackgroundModeExt extends CordovaPlugin {
|
|||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enableWebViewOptimizations() {
|
||||||
|
Thread thread = new Thread(){
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
getApp().runOnUiThread(() -> {
|
||||||
|
View view = webView.getView();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName("org.crosswalk.engine.XWalkCordovaView")
|
||||||
|
.getMethod("onHide")
|
||||||
|
.invoke(view);
|
||||||
|
} catch (Exception e){
|
||||||
|
view.dispatchWindowVisibilityChanged(View.GONE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables battery optimizations for the app.
|
* Disables battery optimizations for the app.
|
||||||
* Requires permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS to function.
|
* Requires permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS to function.
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import android.os.Build;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import androidx.core.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
|
||||||
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
|
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ public class ForegroundService extends Service {
|
|||||||
if (settings.optBoolean("allowClose", false)) {
|
if (settings.optBoolean("allowClose", false)) {
|
||||||
|
|
||||||
final Intent clostAppIntent = new Intent("com.backgroundmode.close" + pkgName);
|
final Intent clostAppIntent = new Intent("com.backgroundmode.close" + pkgName);
|
||||||
final PendingIntent closeIntent = PendingIntent.getBroadcast(context, 1337, clostAppIntent, PendingIntent.FLAG_IMMUTABLE);
|
final PendingIntent closeIntent = PendingIntent.getBroadcast(context, 1337, clostAppIntent, 0);
|
||||||
final String closeIconName = settings.optString("closeIcon", "power");
|
final String closeIconName = settings.optString("closeIcon", "power");
|
||||||
NotificationCompat.Action.Builder closeAction = new NotificationCompat.Action.Builder(getIconResId(closeIconName), settings.optString("closeTitle", "Close"), closeIntent);
|
NotificationCompat.Action.Builder closeAction = new NotificationCompat.Action.Builder(getIconResId(closeIconName), settings.optString("closeTitle", "Close"), closeIntent);
|
||||||
notification.addAction(closeAction.build());
|
notification.addAction(closeAction.build());
|
||||||
@@ -240,7 +240,7 @@ public class ForegroundService extends Service {
|
|||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
PendingIntent contentIntent = PendingIntent.getActivity(
|
PendingIntent contentIntent = PendingIntent.getActivity(
|
||||||
context, NOTIFICATION_ID, intent,
|
context, NOTIFICATION_ID, intent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
|
||||||
notification.setContentIntent(contentIntent);
|
notification.setContentIntent(contentIntent);
|
||||||
|
|||||||
@@ -164,6 +164,14 @@ exports.disableWebViewOptimizations = function()
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.enableWebViewOptimizations = function()
|
||||||
|
{
|
||||||
|
if (this._isAndroid)
|
||||||
|
{
|
||||||
|
cordova.exec(null, null, 'BackgroundModeExt', 'enableWebview', []);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables battery optimazation mode for the app.
|
* Disables battery optimazation mode for the app.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user