diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..485dee64
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.idea
diff --git a/README.md b/README.md
index bde896a8..7b381764 100644
--- a/README.md
+++ b/README.md
@@ -94,7 +94,9 @@ cordova.plugins.backgroundMode.un('EVENT', function);
## Android specifics
### Transit between application states
-Android allows to programmatically move from foreground to background or vice versa.
+Android allows to programmatically move from foreground to background or vice versa.
+
+Note: starting with Android 10, you must request the "Draw on Top" permission from the user or the call to `moveToForeground` will silently fail. You can request it with `cordova.plugins.backgroundMode.requestForegroundPermission();`. This permission isn't necessary for `moveToBackground`
```js
cordova.plugins.backgroundMode.moveToBackground();
@@ -135,6 +137,37 @@ cordova.plugins.backgroundMode.wakeUp();
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.disableBatteryOptimizations();
+```
+
+You can also open the battery optimization settings menu directly, and get the user to set it manually. This may be a better option for devices which may ignore the prompt above.
+
+```js
+cordova.plugins.backgroundMode.openBatteryOptimizationsSettings();
+```
+
+To check if battery optimizations are disabled for the app:
+
+```js
+cordova.plugins.backgroundMode.isIgnoringBatteryOptimizations(function(isIgnoring) {
+ ...
+})
+```
+
+Additionally, you may find that your JS code begins to run less frequently, or not at all while in the background. This can be due to the webview slowing down its execution due to being in the background. The `disableWebViewOptimizations` function can prevent that, but it's important that it is run _after_ the app goes to the background.
+
+```js
+cordova.plugins.backgroundMode.on('activate', function() {
+ cordova.plugins.backgroundMode.disableWebViewOptimizations();
+});
+```
+
### 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.
@@ -145,11 +178,19 @@ The title, text and icon for that notification can be customized as below. Also,
cordova.plugins.backgroundMode.setDefaults({
title: String,
text: String,
- icon: 'icon' // this will look for icon.png in platforms/android/res/drawable|mipmap
- color: String // hex format like 'F14F4D'
+ subText: String, // see https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setSubText(java.lang.CharSequence)
+ icon: 'icon', // this will look for icon.png in platforms/android/res/drawable|mipmap
+ color: String, // hex format like 'F14F4D'
resume: Boolean,
hidden: Boolean,
- bigText: Boolean
+ bigText: Boolean,
+ channelName: String, // Shown when the user views the app's notification settings
+ channelDescription: String, // Shown when the user views the channel's settings
+ allowClose: Boolean, // add a "Close" action to the notification
+ closeIcon: 'power', // An icon shown for the close action
+ closeTitle: 'Close', // The text for the close action
+ showWhen: Boolean, //(Default: true) Show the time since the notification was created
+ visibility: String, // Android only: one of 'private' (default), 'public' or 'secret' (see https://developer.android.com/reference/android/app/Notification.Builder.html#setVisibility(int))
})
```
@@ -174,7 +215,7 @@ Various APIs like playing media or tracking GPS position in background might not
```js
cordova.plugins.backgroundMode.on('activate', function() {
- cordova.plugins.backgroundMode.disableWebViewOptimizations();
+ cordova.plugins.backgroundMode.disableWebViewOptimizations();
});
```
@@ -205,4 +246,4 @@ Made with :yum: from Leipzig
[changelog]: CHANGELOG.md
[apache2_license]: http://opensource.org/licenses/Apache-2.0
[appplant]: http://appplant.de
-[meshfields]: http://meshfields.de
\ No newline at end of file
+[meshfields]: http://meshfields.de
diff --git a/package.json b/package.json
index a0c90c35..470f65e0 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
},
"repository": {
"type": "git",
- "url": "git+https://github.com/katzer/cordova-plugin-background-mode.git"
+ "url": "git+https://github.com/leonardo-fernandes/cordova-plugin-background-mode.git"
},
"keywords": [
"appplant",
@@ -38,4 +38,4 @@
"url": "https://github.com/katzer/cordova-plugin-background-mode/issues"
},
"homepage": "https://github.com/katzer/cordova-plugin-background-mode#readme"
-}
\ No newline at end of file
+}
diff --git a/plugin.xml b/plugin.xml
index 9ffc87d0..7315c7cf 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -9,7 +9,7 @@
Prevent apps from going to sleep in background.
- https://github.com/katzer/cordova-plugin-background-mode.git
+ https://github.com/leonardo-fernandes/cordova-plugin-background-mode.git
appplant, background
@@ -76,6 +76,9 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/android/BackgroundMode.java b/src/android/BackgroundMode.java
index 3ccb5cd1..8c8c167b 100644
--- a/src/android/BackgroundMode.java
+++ b/src/android/BackgroundMode.java
@@ -22,13 +22,14 @@ Licensed to the Apache Software Foundation (ASF) under one
package de.appplant.cordova.plugin.background;
import android.app.Activity;
-import android.content.ComponentName;
-import android.content.Intent;
-import android.content.ServiceConnection;
+import android.content.*;
+import android.os.Bundle;
import android.os.IBinder;
import org.apache.cordova.CallbackContext;
+import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -77,6 +78,24 @@ public void onServiceDisconnected (ComponentName name)
}
};
+ @Override
+ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
+ super.initialize(cordova, webView);
+ IntentFilter filter = new IntentFilter();
+ filter.addAction("com.backgroundmode.close" + cordova.getContext().getPackageName());
+ cordova.getActivity().registerReceiver(receiver, filter);
+
+ }
+
+ private BroadcastReceiver receiver = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ cordova.getActivity().finish();
+
+ }
+ };
+
/**
* Executes the request.
*
@@ -160,7 +179,7 @@ public void onResume (boolean multitasking)
public void onDestroy()
{
stopService();
- android.os.Process.killProcess(android.os.Process.myPid());
+ cordova.getActivity().unregisterReceiver(receiver);
}
/**
diff --git a/src/android/BackgroundModeExt.java b/src/android/BackgroundModeExt.java
index ed765984..06a824e4 100644
--- a/src/android/BackgroundModeExt.java
+++ b/src/android/BackgroundModeExt.java
@@ -34,6 +34,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.net.Uri;
import android.os.Build;
import android.os.PowerManager;
+import android.provider.Settings;
import android.view.View;
import org.apache.cordova.CallbackContext;
@@ -55,6 +56,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.M;
import static android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS;
+import static android.provider.Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS;
import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
@@ -90,6 +92,12 @@ public boolean execute (String action, JSONArray args,
case "battery":
disableBatteryOptimizations();
break;
+ case "batterysettings":
+ openBatterySettings();
+ break;
+ case "optimizationstatus":
+ isIgnoringBatteryOptimizations(callback);
+ break;
case "webview":
disableWebViewOptimizations();
break;
@@ -102,6 +110,9 @@ public boolean execute (String action, JSONArray args,
case "foreground":
moveToForeground();
break;
+ case "requestTopPermissions":
+ requestTopPermissions();
+ break;
case "tasklist":
excludeFromTaskList();
break;
@@ -166,7 +177,7 @@ public void run() {
try {
Thread.sleep(1000);
getApp().runOnUiThread(() -> {
- View view = webView.getEngine().getView();
+ View view = webView.getView();
try {
Class.forName("org.crosswalk.engine.XWalkCordovaView")
@@ -209,6 +220,53 @@ private void disableBatteryOptimizations()
cordova.getActivity().startActivity(intent);
}
+ /**
+ * Opens the Battery Optimization settings screen
+ */
+ private void openBatterySettings()
+ {
+ if (SDK_INT < M)
+ return;
+
+ Activity activity = cordova.getActivity();
+ Intent intent = new Intent(ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
+
+ cordova.getActivity().startActivity(intent);
+ }
+
+ /**
+ * Opens the Battery Optimization settings screen
+ *
+ * @param callback The callback to invoke.
+ */
+ private void isIgnoringBatteryOptimizations(CallbackContext callback)
+ {
+ if (SDK_INT < M)
+ return;
+
+ Activity activity = cordova.getActivity();
+ String pkgName = activity.getPackageName();
+ PowerManager pm = (PowerManager)getService(POWER_SERVICE);
+ boolean isIgnoring = pm.isIgnoringBatteryOptimizations(pkgName);
+ PluginResult res = new PluginResult(Status.OK, isIgnoring);
+
+ callback.sendPluginResult(res);
+ }
+
+ private void requestTopPermissions() {
+ if (SDK_INT >= M) {
+
+ Activity activity = cordova.getActivity();
+ if (Settings.canDrawOverlays(activity.getApplicationContext())) {
+ return;
+ }
+
+ String pkgName = activity.getPackageName();
+ Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + pkgName));
+ activity.startActivity(intent);
+ }
+ }
+
/**
* Opens the system settings dialog where the user can tweak or turn off any
* custom app start settings added by the manufacturer if available.
diff --git a/src/android/ForegroundService.java b/src/android/ForegroundService.java
index 806c9568..c0edae63 100644
--- a/src/android/ForegroundService.java
+++ b/src/android/ForegroundService.java
@@ -23,20 +23,17 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.Service;
+import android.app.*;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
+import android.graphics.drawable.Icon;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.os.PowerManager;
-import android.app.NotificationChannel;
-
import org.json.JSONObject;
+import android.support.v4.app.NotificationCompat;
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
@@ -173,38 +170,55 @@ private Notification makeNotification (JSONObject settings)
{
// use channelid for Oreo and higher
String CHANNEL_ID = "cordova-plugin-background-mode-id";
- if(Build.VERSION.SDK_INT >= 26){
- // The user-visible name of the channel.
- CharSequence name = "cordova-plugin-background-mode";
- // The user-visible description of the channel.
- String description = "cordova-plugin-background-moden notification";
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ // The user-visible name of the channel.
+ CharSequence name = settings.optString("channelName", "cordova-plugin-background-mode");
+ // The user-visible description of the channel.
+ String description = settings.optString("channelDescription", "cordova-plugin-background-moden notification");
- int importance = NotificationManager.IMPORTANCE_LOW;
+ int importance = NotificationManager.IMPORTANCE_LOW;
- NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name,importance);
+ NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
- // Configure the notification channel.
- mChannel.setDescription(description);
+ // Configure the notification channel.
+ mChannel.setDescription(description);
- getNotificationManager().createNotificationChannel(mChannel);
+ getNotificationManager().createNotificationChannel(mChannel);
}
String title = settings.optString("title", NOTIFICATION_TITLE);
String text = settings.optString("text", NOTIFICATION_TEXT);
boolean bigText = settings.optBoolean("bigText", false);
+ String subText = settings.optString("subText", "");
+ String visibility = settings.optString("visibility", "");
Context context = getApplicationContext();
String pkgName = context.getPackageName();
Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(pkgName);
- Notification.Builder notification = new Notification.Builder(context)
+ int smallIcon = getIconResId(settings);
+ if (smallIcon == 0) { //If no icon at all was found, fall back to the app's icon
+ smallIcon = context.getApplicationInfo().icon;
+ }
+
+ NotificationCompat.Builder notification = new NotificationCompat.Builder(context, CHANNEL_ID)
.setContentTitle(title)
.setContentText(text)
.setOngoing(true)
- .setSmallIcon(getIconResId(settings));
+ .setSmallIcon(smallIcon)
+ .setShowWhen(settings.optBoolean("showWhen", true));
+
+ if (!subText.equals("")) {
+ notification.setSubText(subText);
+ }
- if(Build.VERSION.SDK_INT >= 26){
- notification.setChannelId(CHANNEL_ID);
+ if (settings.optBoolean("allowClose", false)) {
+
+ final Intent clostAppIntent = new Intent("com.backgroundmode.close" + pkgName);
+ final PendingIntent closeIntent = PendingIntent.getBroadcast(context, 1337, clostAppIntent, 0);
+ 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());
}
if (settings.optBoolean("hidden", true)) {
@@ -213,7 +227,11 @@ private Notification makeNotification (JSONObject settings)
if (bigText || text.contains("\n")) {
notification.setStyle(
- new Notification.BigTextStyle().bigText(text));
+ new NotificationCompat.BigTextStyle().bigText(text));
+ }
+
+ if (!visibility.equals("")) {
+ notification.setVisibility(getVisibility(visibility));
}
setColor(notification, settings);
@@ -251,23 +269,40 @@ protected void updateNotification (JSONObject settings)
}
/**
- * Retrieves the resource ID of the app icon.
+ * Retrieves the resource ID of the sent icon name
*
- * @param settings A JSON dict containing the icon name.
+ * @param name Name of the resource to return
*/
- private int getIconResId (JSONObject settings)
- {
- String icon = settings.optString("icon", NOTIFICATION_ICON);
+ private int getIconResId(String name) {
+ int resId = getIconResId(name, "mipmap");
- int resId = getIconResId(icon, "mipmap");
+ if (resId == 0) {
+ resId = getIconResId(name, "drawable");
+ }
if (resId == 0) {
- resId = getIconResId(icon, "drawable");
+ resId = getIconResId("icon", "mipmap");
}
+ if (resId == 0) {
+ resId = getIconResId("icon", "drawable");
+ }
+
+
return resId;
}
+ /**
+ * Retrieves the resource ID of the app icon.
+ *
+ * @param settings A JSON dict containing the icon name.
+ */
+ private int getIconResId(JSONObject settings) {
+ String icon = settings.optString("icon", NOTIFICATION_ICON);
+
+ return getIconResId(icon);
+ }
+
/**
* Retrieve resource id of the specified icon.
*
@@ -281,15 +316,26 @@ private int getIconResId (String icon, String type)
Resources res = getResources();
String pkgName = getPackageName();
- int resId = res.getIdentifier(icon, type, pkgName);
+ return res.getIdentifier(icon, type, pkgName);
+ }
- if (resId == 0) {
- resId = res.getIdentifier("icon", type, pkgName);
+ /**
+ * Get the visibility constant from a string.
+ *
+ * @param visibility one of 'public', 'private', 'secret'
+ *
+ * @return The visibility constant if a match is found, 'private' otherwise
+ */
+ private int getVisibility (String visibility)
+ {
+ if (visibility.equals("public")) {
+ return Notification.VISIBILITY_PUBLIC;
+ } else if (visibility.equals("secret")) {
+ return Notification.VISIBILITY_SECRET;
+ } else {
+ return Notification.VISIBILITY_PRIVATE;
}
-
- return resId;
}
-
/**
* Set notification color if its supported by the SDK.
*
@@ -297,8 +343,8 @@ private int getIconResId (String icon, String type)
* @param settings A JSON dict containing the color definition (red: FF0000)
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
- private void setColor (Notification.Builder notification, JSONObject settings)
- {
+ private void setColor(NotificationCompat.Builder notification,
+ JSONObject settings) {
String hex = settings.optString("color", null);
diff --git a/src/android/res/drawable-hdpi/power.png b/src/android/res/drawable-hdpi/power.png
new file mode 100644
index 00000000..31b32c87
Binary files /dev/null and b/src/android/res/drawable-hdpi/power.png differ
diff --git a/src/android/res/drawable-mdpi/power.png b/src/android/res/drawable-mdpi/power.png
new file mode 100644
index 00000000..78a474b8
Binary files /dev/null and b/src/android/res/drawable-mdpi/power.png differ
diff --git a/src/android/res/drawable-xhdpi/power.png b/src/android/res/drawable-xhdpi/power.png
new file mode 100644
index 00000000..9026845a
Binary files /dev/null and b/src/android/res/drawable-xhdpi/power.png differ
diff --git a/src/android/res/drawable-xxhdpi/power.png b/src/android/res/drawable-xxhdpi/power.png
new file mode 100644
index 00000000..812b1a4d
Binary files /dev/null and b/src/android/res/drawable-xxhdpi/power.png differ
diff --git a/src/android/res/drawable/power.xml b/src/android/res/drawable/power.xml
new file mode 100644
index 00000000..1f717634
--- /dev/null
+++ b/src/android/res/drawable/power.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/src/ios/APPBackgroundMode.m b/src/ios/APPBackgroundMode.m
index e0792ccc..f28d1b27 100644
--- a/src/ios/APPBackgroundMode.m
+++ b/src/ios/APPBackgroundMode.m
@@ -174,6 +174,9 @@ - (void) configureAudioSession
// even another app starts playing sound
[session setCategory:AVAudioSessionCategoryPlayback
error:NULL];
+ // Prevent sound/music from stopping when opening the app. Also prevents embedded videos from pausing when unmuted.
+ [session setCategory:AVAudioSessionCategoryAmbient
+ error:NULL];
// Active the audio session
[session setActive:YES error:NULL];
@@ -221,7 +224,7 @@ - (void) fireEvent:(NSString*)event
NSString* flag = [NSString stringWithFormat:@"%@._isActive=%@;",
kAPPBackgroundJsNamespace, active];
-
+
NSString* depFn = [NSString stringWithFormat:@"%@.on('%@');",
kAPPBackgroundJsNamespace, event];
@@ -241,7 +244,16 @@ - (void) fireEvent:(NSString*)event
*/
+ (NSString*) wkProperty
{
- NSString* str = @"YWx3YXlzUnVuc0F0Rm9yZWdyb3VuZFByaW9yaXR5";
+ NSString * str = @"";
+ if (@available(iOS 12.2, *)) {
+ // do stuff for iOS 12.2 and newer
+ NSLog(@"iOS 12.2+ detected");
+ str = @"YWx3YXlzUnVuc0F0Rm9yZWdyb3VuZFByaW9yaXR5";
+ } else {
+ // do stuff for iOS 12.1 and older
+ NSLog(@"iOS Below 12.2 detected");
+ str = @"X2Fsd2F5c1J1bnNBdEZvcmVncm91bmRQcmlvcml0eQ==";
+ }
NSData* data = [[NSData alloc] initWithBase64EncodedString:str options:0];
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
diff --git a/src/windows/BackgroundModeProxy.js b/src/windows/BackgroundModeProxy.js
new file mode 100644
index 00000000..b151ae1f
--- /dev/null
+++ b/src/windows/BackgroundModeProxy.js
@@ -0,0 +1,123 @@
+/*
+ Copyright 2013 Sebastián Katzer
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+var plugin = cordova.plugins.backgroundMode;
+
+var Uri = Windows.Foundation.Uri,
+ MediaSource = Windows.Media.Core.MediaSource,
+ MediaPlaybackItem = Windows.Media.Playback.MediaPlaybackItem,
+ MediaPlaybackList = Windows.Media.Playback.MediaPlaybackList,
+ AudioCategory = Windows.Media.Playback.MediaPlayerAudioCategory,
+ MediaPlayer = Windows.Media.Playback.MediaPlayer,
+ WebUIApplication = Windows.UI.WebUI.WebUIApplication;
+
+/**
+ * Activates the background mode. When activated the application
+ * will be prevented from going to sleep while in background
+ * for the next time.
+ *
+ * @param [ Function ] success The success callback to use.
+ * @param [ Function ] error The error callback to use.
+ *
+ * @return [ Void ]
+ */
+exports.enable = function (success, error) {
+ success();
+};
+
+/**
+ * Deactivates the background mode. When deactivated the application
+ * will not stay awake while in background.
+ *
+ * @param [ Function ] success The success callback to use.
+ * @param [ Function ] error The error callback to use.
+ *
+ * @return [ Void ]
+ */
+exports.disable = function (success, error) {
+ exports.stopKeepingAwake();
+ success();
+};
+
+/**
+ * Keep the app awake.
+ *
+ * @return [ Void ]
+ */
+exports.keepAwake = function () {
+ if (!plugin.isEnabled() || plugin.isActive())
+ return;
+
+ exports.configureAudioPlayer();
+ exports.audioPlayer.play();
+
+ plugin._isActive = true;
+ plugin.fireEvent('activate');
+};
+
+/**
+ * Let the app going to sleep.
+ *
+ * @return [ Void ]
+ */
+exports.stopKeepingAwake = function () {
+ if (!exports.audioPlayer)
+ return;
+
+ exports.audioPlayer.close();
+ exports.audioPlayer = null;
+
+ cordova.plugins.backgroundMode._isActive = false;
+ cordova.plugins.backgroundMode.fireEvent('deactivate');
+};
+
+/**
+ * Configure the audio player for playback in background.
+ *
+ * @return [ Void ]
+ */
+exports.configureAudioPlayer = function () {
+ if (exports.audioPlayer)
+ return;
+
+ var pkg = Windows.ApplicationModel.Package.current,
+ pkgName = pkg.id.name;
+
+ var audioPlayer = new MediaPlayer(),
+ audioFile = new Uri('ms-appx://' + pkgName + '/appbeep.wma'),
+ audioSource = MediaSource.createFromUri(audioFile),
+ playList = new MediaPlaybackList();
+
+ playList.items.append(new MediaPlaybackItem(audioSource));
+ playList.autoRepeatEnabled = true;
+
+ audioPlayer.source = playList;
+ audioPlayer.autoPlay = false;
+ audioPlayer.audioCategory = AudioCategory.soundEffects;
+ audioPlayer.volume = 0;
+
+ exports.audioPlayer = audioPlayer;
+};
+
+WebUIApplication.addEventListener('enteredbackground', exports.keepAwake, false);
+WebUIApplication.addEventListener('leavingbackground', exports.stopKeepingAwake, false);
+
+cordova.commandProxy.add('BackgroundMode', exports);
diff --git a/www/background-mode.js b/www/background-mode.js
index fff3f8d3..44644258 100644
--- a/www/background-mode.js
+++ b/www/background-mode.js
@@ -177,6 +177,38 @@ exports.disableBatteryOptimizations = function()
}
};
+/**
+ * Opens the system settings screen for battery optimization, allowing the user to
+ * manually change the optimization settings.
+ *
+ * @return [ Void ]
+ */
+exports.openBatteryOptimizationsSettings = function()
+{
+ if (this._isAndroid)
+ {
+ cordova.exec(null, null, 'BackgroundModeExt', 'batterysettings', []);
+ }
+};
+
+/**
+ * Opens the system settings screen for battery optimization, allowing the user to
+ * manually change the optimization settings.
+ *
+ * @return [ Void ]
+ */
+exports.isIgnoringBatteryOptimizations = function(callback)
+{
+ if (this._isAndroid)
+ {
+ cordova.exec(callback, null, 'BackgroundModeExt', 'optimizationstatus', []);
+ }
+ else
+ {
+ callback(true);
+ }
+};
+
/**
* Opens the system settings dialog where the user can tweak or turn off any
* custom app start settings added by the manufacturer if available.
@@ -220,6 +252,17 @@ exports.moveToForeground = function()
}
};
+/**
+ * Requests permission to "draw on top" which is necessary for the "moveToForeground" method in Android 10+
+ *
+ * @return [ Void ]
+ */
+exports.requestForegroundPermission = function() {
+ if (this._isAndroid) {
+ cordova.exec(null, null, 'BackgroundModeExt', 'requestTopPermissions', []);
+ }
+};
+
/**
* Exclude the app from the recent tasks list (Android only).
*
@@ -408,16 +451,24 @@ exports._isActive = false;
*
* Default values of all available options.
*/
-exports._defaults =
-{
- title: 'App is running in background',
- text: 'Doing heavy tasks.',
- bigText: false,
- resume: true,
- silent: false,
- hidden: true,
- color: undefined,
- icon: 'icon'
+
+exports._defaults = {
+ title: 'App is running in background',
+ text: 'Doing heavy tasks.',
+ subText: '',
+ bigText: false,
+ resume: true,
+ silent: false,
+ hidden: true,
+ color: undefined,
+ icon: 'icon',
+ channelName: 'cordova-plugin-background-mode',
+ channelDescription: 'cordova-plugin-background-moden notification',
+ allowClose: false,
+ closeIcon: 'power',
+ closeTitle: 'Close',
+ showWhen: true,
+ visibility: undefined
};
/**