forked from Github/cordova-plugin-run-in-background
Compare commits
2 Commits
2-large-ic
...
issue/#5-f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48a06fc3eb | ||
|
|
a3063aed68 |
@@ -120,6 +120,14 @@ cordova.plugins.backgroundMode.wakeUp();
|
|||||||
cordova.plugins.backgroundMode.unlock();
|
cordova.plugins.backgroundMode.unlock();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Request to disable battery optimizations
|
||||||
|
Starting in Android 8, apps can be put to sleep to conserve battery. When this happens (usually after 5 minutes or so), the background task is killed. This will cause things like MQTT connections to break.
|
||||||
|
This method will show a permission prompt for the user (only if the app hasn't been granted permission) to ignore the optimization.
|
||||||
|
|
||||||
|
```js
|
||||||
|
cordova.plugins.backgroundMode.disableWebViewOptimizations();
|
||||||
|
```
|
||||||
|
|
||||||
### Notification
|
### 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.
|
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.
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import android.app.*;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@@ -190,7 +189,6 @@ public class ForegroundService extends Service {
|
|||||||
String text = settings.optString("text", NOTIFICATION_TEXT);
|
String text = settings.optString("text", NOTIFICATION_TEXT);
|
||||||
boolean bigText = settings.optBoolean("bigText", false);
|
boolean bigText = settings.optBoolean("bigText", false);
|
||||||
String subText = settings.optString("subText", "");
|
String subText = settings.optString("subText", "");
|
||||||
String largeIcon = settings.optString("largeIcon", null);
|
|
||||||
|
|
||||||
Context context = getApplicationContext();
|
Context context = getApplicationContext();
|
||||||
String pkgName = context.getPackageName();
|
String pkgName = context.getPackageName();
|
||||||
@@ -208,10 +206,6 @@ public class ForegroundService extends Service {
|
|||||||
notification.setSubText(subText);
|
notification.setSubText(subText);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (largeIcon != null) {
|
|
||||||
notification.setLargeIcon(BitmapFactory.decodeResource(getResources(), getIconResId(largeIcon)));
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
|
|||||||
NSString* flag = [NSString stringWithFormat:@"%@._isActive=%@;",
|
NSString* flag = [NSString stringWithFormat:@"%@._isActive=%@;",
|
||||||
kAPPBackgroundJsNamespace, active];
|
kAPPBackgroundJsNamespace, active];
|
||||||
|
|
||||||
NSString* depFn = [NSString stringWithFormat:@"%@.on%@();",
|
NSString* depFn = [NSString stringWithFormat:@"%@.on('%@');",
|
||||||
kAPPBackgroundJsNamespace, event];
|
kAPPBackgroundJsNamespace, event];
|
||||||
|
|
||||||
NSString* fn = [NSString stringWithFormat:@"%@.fireEvent('%@');",
|
NSString* fn = [NSString stringWithFormat:@"%@.fireEvent('%@');",
|
||||||
|
|||||||
@@ -419,7 +419,6 @@ exports._defaults = {
|
|||||||
hidden: true,
|
hidden: true,
|
||||||
color: undefined,
|
color: undefined,
|
||||||
icon: 'icon',
|
icon: 'icon',
|
||||||
largeIcon: undefined,
|
|
||||||
channelName: 'cordova-plugin-background-mode',
|
channelName: 'cordova-plugin-background-mode',
|
||||||
channelDescription: 'cordova-plugin-background-moden notification',
|
channelDescription: 'cordova-plugin-background-moden notification',
|
||||||
allowClose: false,
|
allowClose: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user