Merge pull request #834 from MilosKozak/notif-channels
Notification channels
This commit is contained in:
commit
bf32b1e065
3 changed files with 60 additions and 3 deletions
|
@ -1,11 +1,14 @@
|
|||
package info.nightscout.androidaps.plugins.Loop;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.TaskStackBuilder;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.crashlytics.android.answers.CustomEvent;
|
||||
|
@ -48,6 +51,9 @@ import info.nightscout.utils.SP;
|
|||
public class LoopPlugin extends PluginBase {
|
||||
private static Logger log = LoggerFactory.getLogger(LoopPlugin.class);
|
||||
|
||||
public static final String CHANNEL_ID = "AndroidAPS-Openloop";
|
||||
|
||||
|
||||
protected static LoopPlugin loopPlugin;
|
||||
|
||||
public static LoopPlugin getPlugin() {
|
||||
|
@ -90,9 +96,22 @@ public class LoopPlugin extends PluginBase {
|
|||
@Override
|
||||
protected void onStart() {
|
||||
MainApp.bus().register(this);
|
||||
createNotificationChannel();
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
private void createNotificationChannel() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
|
||||
NotificationManager mNotificationManager =
|
||||
(NotificationManager) MainApp.instance().getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
@SuppressLint("WrongConstant") NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
|
||||
CHANNEL_ID,
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
mNotificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
|
@ -322,7 +341,7 @@ public class LoopPlugin extends PluginBase {
|
|||
} else {
|
||||
if (result.isChangeRequested() && allowNotification) {
|
||||
NotificationCompat.Builder builder =
|
||||
new NotificationCompat.Builder(MainApp.instance().getApplicationContext());
|
||||
new NotificationCompat.Builder(MainApp.instance().getApplicationContext(), CHANNEL_ID);
|
||||
builder.setSmallIcon(R.drawable.notif_icon)
|
||||
.setContentTitle(MainApp.sResources.getString(R.string.openloop_newsuggestion))
|
||||
.setContentText(resultAfterConstraints.toString())
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.Overview.notifications;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -8,6 +10,7 @@ import android.graphics.BitmapFactory;
|
|||
import android.media.AudioAttributes;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
@ -28,11 +31,15 @@ import info.nightscout.utils.SP;
|
|||
*/
|
||||
|
||||
public class NotificationStore {
|
||||
|
||||
public static final String CHANNEL_ID = "AndroidAPS-Overview";
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(NotificationStore.class);
|
||||
public List<Notification> store = new ArrayList<Notification>();
|
||||
public long snoozedUntil = 0L;
|
||||
|
||||
public NotificationStore() {
|
||||
createNotificationChannel();
|
||||
}
|
||||
|
||||
public class NotificationComparator implements Comparator<Notification> {
|
||||
|
@ -110,7 +117,7 @@ public class NotificationStore {
|
|||
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.blueowl);
|
||||
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
|
||||
NotificationCompat.Builder notificationBuilder =
|
||||
new NotificationCompat.Builder(context)
|
||||
new NotificationCompat.Builder(context, CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setLargeIcon(largeIcon)
|
||||
.setContentText(n.text)
|
||||
|
@ -127,4 +134,17 @@ public class NotificationStore {
|
|||
}
|
||||
mgr.notify(n.id, notificationBuilder.build());
|
||||
}
|
||||
|
||||
private void createNotificationChannel() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
|
||||
NotificationManager mNotificationManager =
|
||||
(NotificationManager) MainApp.instance().getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
@SuppressLint("WrongConstant") NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
|
||||
CHANNEL_ID,
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
mNotificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package info.nightscout.androidaps.plugins.Persistentnotification;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Build;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
|
||||
|
@ -41,6 +44,8 @@ import info.nightscout.utils.DecimalFormatter;
|
|||
|
||||
public class PersistentNotificationPlugin extends PluginBase {
|
||||
|
||||
public static final String CHANNEL_ID = "AndroidAPS-Ongoing";
|
||||
|
||||
private static final int ONGOING_NOTIFICATION_ID = 4711;
|
||||
private final Context ctx;
|
||||
|
||||
|
@ -57,10 +62,23 @@ public class PersistentNotificationPlugin extends PluginBase {
|
|||
@Override
|
||||
protected void onStart() {
|
||||
MainApp.bus().register(this);
|
||||
createNotificationChannel();
|
||||
updateNotification();
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
private void createNotificationChannel() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
|
||||
NotificationManager mNotificationManager =
|
||||
(NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
@SuppressLint("WrongConstant") NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
|
||||
CHANNEL_ID,
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
mNotificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
MainApp.bus().unregister(this);
|
||||
|
@ -118,7 +136,7 @@ public class PersistentNotificationPlugin extends PluginBase {
|
|||
line3 += " - " + MainApp.getConfigBuilder().getProfileName();
|
||||
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, CHANNEL_ID);
|
||||
builder.setOngoing(true);
|
||||
builder.setCategory(NotificationCompat.CATEGORY_STATUS);
|
||||
builder.setSmallIcon(R.drawable.ic_notification);
|
||||
|
|
Loading…
Reference in a new issue