Commit d5c0072c by Sebastián Katzer

Support for Android 4.4 and Android 5+

parent 77ecc164
......@@ -21,6 +21,7 @@
package de.appplant.cordova.plugin.notification;
import android.annotation.SuppressLint;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
......@@ -38,6 +39,7 @@ import java.util.Set;
import de.appplant.cordova.plugin.badge.BadgeImpl;
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.O;
import static android.support.v4.app.NotificationManagerCompat.IMPORTANCE_DEFAULT;
import static de.appplant.cordova.plugin.notification.Notification.PREF_KEY_ID;
......@@ -103,6 +105,7 @@ public final class Manager {
/**
* TODO: temporary
*/
@SuppressLint("WrongConstant")
private void createDefaultChannel() {
NotificationManager mgr = getNotMgr();
......@@ -224,8 +227,8 @@ public final class Manager {
if (type == Notification.Type.ALL)
return getIds();
StatusBarNotification[] activeToasts = getNotMgr().getActiveNotifications();
List<Integer> activeIds = new ArrayList<Integer>();
StatusBarNotification[] activeToasts = getActiveNotifications();
List<Integer> activeIds = new ArrayList<Integer>();
for (StatusBarNotification toast : activeToasts) {
activeIds.add(toast.getId());
......@@ -390,6 +393,17 @@ public final class Manager {
}
/**
* Get all active status bar notifications.
*/
StatusBarNotification[] getActiveNotifications() {
if (SDK_INT >= M) {
return getNotMgr().getActiveNotifications();
} else {
return new StatusBarNotification[0];
}
}
/**
* Shared private preferences for the application.
*/
private SharedPreferences getPrefs () {
......@@ -411,11 +425,4 @@ public final class Manager {
return NotificationManagerCompat.from(context);
}
/**
* Notification manager compat for the application.
*/
private NotificationManagerCompat getNotMgrCompat () {
return NotificationManagerCompat.from(context);
}
}
......@@ -46,6 +46,8 @@ import java.util.Set;
import static android.app.AlarmManager.RTC;
import static android.app.AlarmManager.RTC_WAKEUP;
import static android.app.PendingIntent.FLAG_CANCEL_CURRENT;
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.M;
import static android.support.v4.app.NotificationManagerCompat.IMPORTANCE_MAX;
import static android.support.v4.app.NotificationManagerCompat.IMPORTANCE_MIN;
......@@ -138,8 +140,9 @@ public final class Notification {
* Notification type can be one of triggered or scheduled.
*/
public Type getType () {
StatusBarNotification[] toasts = getNotMgr().getActiveNotifications();
int id = getId();
Manager mgr = Manager.getInstance(context);
StatusBarNotification[] toasts = mgr.getActiveNotifications();
int id = getId();
for (StatusBarNotification toast : toasts) {
if (toast.getId() == id) {
......@@ -202,7 +205,11 @@ public final class Notification {
mgr.setExact(RTC, time, pi);
break;
case IMPORTANCE_MAX:
mgr.setExactAndAllowWhileIdle(RTC_WAKEUP, time, pi);
if (SDK_INT >= M) {
mgr.setExactAndAllowWhileIdle(RTC_WAKEUP, time, pi);
} else {
mgr.setExact(RTC, time, pi);
}
break;
default:
mgr.setExact(RTC_WAKEUP, time, pi);
......
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