Dismiss notification service

This commit is contained in:
AdrianLxM 2017-11-06 14:09:03 +01:00
parent 87ea412516
commit d990d59ddf
2 changed files with 51 additions and 11 deletions

View file

@ -0,0 +1,33 @@
package info.nightscout.androidaps.plugins.Overview;
import android.app.IntentService;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.annotation.Nullable;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.utils.SafeParse;
public class DismissNotificationService extends IntentService {
/**
* Creates an IntentService. Invoked by your subclass's constructor.
*
* @param name Used to name the worker thread, important only for debugging.
*/
public DismissNotificationService(String name) {
super(name);
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
MainApp.bus().post(new EventDismissNotification(intent.getIntExtra("alertID", -1)));
}
public static PendingIntent deleteIntent(int id){
Intent intent = new Intent(MainApp.instance(), DismissNotificationService.class);
intent.putExtra("alertID", id);
return PendingIntent.getService(MainApp.instance(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
}

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.Overview;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
@ -22,7 +23,6 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.AlarmSoundService;
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
//Added by Rumen for snooze time
import info.nightscout.utils.SP;
/**
@ -57,22 +57,26 @@ public class NotificationStore {
}
}
store.add(n);
if (SP.getBoolean(MainApp.sResources.getString(R.string.key_raise_urgent_alarms_as_android_notification), false)
&& n.level == Notification.URGENT) {
raiseSystemNotification(n);
} else if (n.soundId != null) {
} else {
if (n.soundId != null) {
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
alarm.putExtra("soundid", n.soundId);
MainApp.instance().startService(alarm);
}
store.add(n);
//Only pipe through to wear if no system notification is raised (should show on wear anyways)
WearPlugin wearPlugin = MainApp.getSpecificPlugin(WearPlugin.class);
if(wearPlugin!= null && wearPlugin.isEnabled()) {
wearPlugin.overviewNotification(n.id, "OverviewNotification:\n" + n.text);
}
}
Collections.sort(store, new NotificationComparator());
}
@ -89,10 +93,12 @@ public class NotificationStore {
.setContentText(n.text)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVibrate(new long[] { 1000, 1000, 1000, 1000})
.setSound(sound, AudioAttributes.USAGE_ALARM);
.setSound(sound, AudioAttributes.USAGE_ALARM)
.setDeleteIntent(DismissNotificationService.deleteIntent(n.id));
mgr.notify(n.id, notificationBuilder.build());
}
public boolean remove(int id) {
for (int i = 0; i < store.size(); i++) {
if (get(i).id == id) {
@ -131,3 +137,4 @@ public class NotificationStore {
}
}
}