Commit 620d3fc4 by Sebastián Katzer

Added wakeup options for Android [See #627]

parent cf99f31e
...@@ -98,7 +98,7 @@ A notification does have a set of configurable properties. Not all of them are s ...@@ -98,7 +98,7 @@ A notification does have a set of configurable properties. Not all of them are s
| id | data | actionGroupId | summary | led | showWhen | channel | actions | | id | data | actionGroupId | summary | led | showWhen | channel | actions |
| text | icon | attachments | smallIcon | color | defaults | launch | groupSummary | | text | icon | attachments | smallIcon | color | defaults | launch | groupSummary |
| title | silent | progressBar | sticky | vibrate | priority | mediaSession | foreground | | title | silent | progressBar | sticky | vibrate | priority | mediaSession | foreground |
| sound | trigger | group | autoClear | lockscreen | number | badge | | sound | trigger | group | autoClear | lockscreen | number | badge | wakeup |
For their default values see: For their default values see:
......
...@@ -140,6 +140,7 @@ ...@@ -140,6 +140,7 @@
<config-file target="AndroidManifest.xml" parent="/manifest"> <config-file target="AndroidManifest.xml" parent="/manifest">
<!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> --> <!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
</config-file> </config-file>
<source-file <source-file
......
...@@ -21,13 +21,19 @@ ...@@ -21,13 +21,19 @@
package de.appplant.cordova.plugin.localnotification; package de.appplant.cordova.plugin.localnotification;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager;
import de.appplant.cordova.plugin.notification.Builder; import de.appplant.cordova.plugin.notification.Builder;
import de.appplant.cordova.plugin.notification.Manager; import de.appplant.cordova.plugin.notification.Manager;
import de.appplant.cordova.plugin.notification.Notification; import de.appplant.cordova.plugin.notification.Notification;
import de.appplant.cordova.plugin.notification.Options;
import de.appplant.cordova.plugin.notification.receiver.AbstractTriggerReceiver; import de.appplant.cordova.plugin.notification.receiver.AbstractTriggerReceiver;
import static android.content.Context.POWER_SERVICE;
import static android.os.PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY;
/** /**
* The alarm receiver is triggered when a scheduled alarm is fired. This class * The alarm receiver is triggered when a scheduled alarm is fired. This class
* reads the information in the intent and displays this information in the * reads the information in the intent and displays this information in the
...@@ -46,10 +52,16 @@ public class TriggerReceiver extends AbstractTriggerReceiver { ...@@ -46,10 +52,16 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
@Override @Override
public void onTrigger (Notification notification, Bundle bundle) { public void onTrigger (Notification notification, Bundle bundle) {
boolean isUpdate = bundle.getBoolean(Notification.EXTRA_UPDATE, false); boolean isUpdate = bundle.getBoolean(Notification.EXTRA_UPDATE, false);
int badge = notification.getOptions().getBadgeNumber(); Context context = notification.getContext();
Options options = notification.getOptions();
int badge = options.getBadgeNumber();
if (badge > 0) { if (badge > 0) {
Manager.getInstance(notification.getContext()).setBadge(badge); Manager.getInstance(context).setBadge(badge);
}
if (options.shallWakeUp()) {
wakeUp(context);
} }
notification.show(); notification.show();
...@@ -60,6 +72,28 @@ public class TriggerReceiver extends AbstractTriggerReceiver { ...@@ -60,6 +72,28 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
} }
/** /**
* Wakeup the device.
*
* @param context The application context.
*/
private void wakeUp (Context context) {
PowerManager pm = (PowerManager) context.getSystemService(POWER_SERVICE);
if (pm == null)
return;
int level = PowerManager.SCREEN_DIM_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP;
PowerManager.WakeLock wakeLock = pm.newWakeLock(
level,"LocalNotification");
wakeLock.setReferenceCounted(false);
wakeLock.acquire(1000);
wakeLock.release(RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY);
}
/**
* Build notification specified by options. * Build notification specified by options.
* *
* @param builder Notification builder. * @param builder Notification builder.
......
...@@ -193,6 +193,13 @@ public final class Options { ...@@ -193,6 +193,13 @@ public final class Options {
} }
/** /**
* wakeup flag for the notification.
*/
public boolean shallWakeUp() {
return options.optBoolean("wakeup", true);
}
/**
* The channel id of that notification. * The channel id of that notification.
*/ */
String getChannel() { String getChannel() {
...@@ -335,7 +342,7 @@ public final class Options { ...@@ -335,7 +342,7 @@ public final class Options {
/** /**
* Icon resource ID for the local notification. * Icon resource ID for the local notification.
*/ */
public boolean hasLargeIcon () { boolean hasLargeIcon() {
String icon = options.optString("icon", null); String icon = options.optString("icon", null);
return icon != null; return icon != null;
} }
......
...@@ -54,7 +54,8 @@ exports._defaults = { ...@@ -54,7 +54,8 @@ exports._defaults = {
text : '', text : '',
title : '', title : '',
trigger : { type : 'calendar' }, trigger : { type : 'calendar' },
vibrate : false vibrate : false,
wakeup : true
}; };
// Listener // Listener
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment