forked from Github/cordova-plugin-run-in-background
Compare commits
4 Commits
kerr/add-e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e11ee4f432 | ||
|
|
d1d6396c07 | ||
|
|
8bc19edeb4 | ||
|
|
df990e762f |
@@ -1,4 +1,9 @@
|
||||
## 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)
|
||||
- Check if screen is off on Android
|
||||
- Wake-up device on Android
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cordova-plugin-background-mode",
|
||||
"version": "0.7.3",
|
||||
"version": "0.8.0",
|
||||
"description": "Prevent apps from going to sleep in background.",
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-background-mode",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="cordova-plugin-background-mode"
|
||||
version="0.7.3">
|
||||
version="0.8.0">
|
||||
|
||||
<name>BackgroundMode</name>
|
||||
|
||||
@@ -93,7 +93,8 @@
|
||||
src="src/android/ForegroundService.java"
|
||||
target-dir="src/de/appplant/cordova/plugin/background" />
|
||||
|
||||
<framework src="com.android.support:support-compat:27.1.1" />
|
||||
<framework src="androidx.core:core:1.0.0" />
|
||||
<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-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" />
|
||||
|
||||
@@ -101,9 +101,6 @@ public class BackgroundModeExt extends CordovaPlugin {
|
||||
case "webview":
|
||||
disableWebViewOptimizations();
|
||||
break;
|
||||
case "enableWebview":
|
||||
enableWebViewOptimizations();
|
||||
break;
|
||||
case "appstart":
|
||||
openAppStart(args.opt(0));
|
||||
break;
|
||||
@@ -199,31 +196,6 @@ public class BackgroundModeExt extends CordovaPlugin {
|
||||
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.
|
||||
* Requires permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS to function.
|
||||
|
||||
@@ -33,7 +33,7 @@ import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.os.PowerManager;
|
||||
import org.json.JSONObject;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
|
||||
|
||||
@@ -215,7 +215,7 @@ public class ForegroundService extends Service {
|
||||
if (settings.optBoolean("allowClose", false)) {
|
||||
|
||||
final Intent clostAppIntent = new Intent("com.backgroundmode.close" + pkgName);
|
||||
final PendingIntent closeIntent = PendingIntent.getBroadcast(context, 1337, clostAppIntent, 0);
|
||||
final PendingIntent closeIntent = PendingIntent.getBroadcast(context, 1337, clostAppIntent, PendingIntent.FLAG_IMMUTABLE);
|
||||
final String closeIconName = settings.optString("closeIcon", "power");
|
||||
NotificationCompat.Action.Builder closeAction = new NotificationCompat.Action.Builder(getIconResId(closeIconName), settings.optString("closeTitle", "Close"), closeIntent);
|
||||
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);
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(
|
||||
context, NOTIFICATION_ID, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||
|
||||
|
||||
notification.setContentIntent(contentIntent);
|
||||
|
||||
@@ -164,14 +164,6 @@ exports.disableWebViewOptimizations = function()
|
||||
}
|
||||
};
|
||||
|
||||
exports.enableWebViewOptimizations = function()
|
||||
{
|
||||
if (this._isAndroid)
|
||||
{
|
||||
cordova.exec(null, null, 'BackgroundModeExt', 'enableWebview', []);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Disables battery optimazation mode for the app.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user