(#2240) Fixed open loop notifications on wear os - support for Android O channel config
This commit is contained in:
parent
5f19e32504
commit
85ee3519fd
1 changed files with 32 additions and 14 deletions
|
@ -1,24 +1,22 @@
|
|||
package info.nightscout.androidaps.data;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.preference.PreferenceManager;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.api.GoogleApiClient;
|
||||
|
@ -36,8 +34,11 @@ import com.google.android.gms.wearable.NodeApi;
|
|||
import com.google.android.gms.wearable.Wearable;
|
||||
import com.google.android.gms.wearable.WearableListenerService;
|
||||
|
||||
import info.nightscout.androidaps.interaction.AAPSPreferences;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interaction.AAPSPreferences;
|
||||
import info.nightscout.androidaps.interaction.actions.AcceptActivity;
|
||||
import info.nightscout.androidaps.interaction.actions.CPPActivity;
|
||||
import info.nightscout.androidaps.interaction.utils.Persistence;
|
||||
|
@ -79,6 +80,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
|
||||
|
||||
private static final String ACTION_RESEND_BULK = "com.dexdrip.stephenblack.nightwatch.RESEND_BULK_DATA";
|
||||
private static final String AAPS_NOTIFY_CHANNEL_ID = "AndroidAPS-Openloop";
|
||||
|
||||
GoogleApiClient googleApiClient;
|
||||
private long lastRequest = 0;
|
||||
|
@ -552,13 +554,29 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
}
|
||||
|
||||
private void notifyChangeRequest(String title, String message, String actionstring) {
|
||||
// Create the NotificationChannel, but only on API 26+ because
|
||||
// the NotificationChannel class is new and not in the support library
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
CharSequence name = "AAPS Open Loop";
|
||||
String description = "Open Loop request notiffication";//getString(R.string.channel_description);
|
||||
NotificationChannel channel = new NotificationChannel(AAPS_NOTIFY_CHANNEL_ID, name, NotificationManager.IMPORTANCE_HIGH);
|
||||
channel.setDescription(description);
|
||||
channel.enableVibration(true);
|
||||
|
||||
Notification.Builder builder =
|
||||
new Notification.Builder(this); //,"AndroidAPS-Openloop");
|
||||
builder.setSmallIcon(R.drawable.notif_icon)
|
||||
// Register the channel with the system; you can't change the importance
|
||||
// or other notification behaviors after this
|
||||
NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
NotificationCompat.Builder builder =
|
||||
new NotificationCompat.Builder(this, AAPS_NOTIFY_CHANNEL_ID);
|
||||
|
||||
builder = builder.setSmallIcon(R.drawable.notif_icon)
|
||||
.setContentTitle(title)
|
||||
.setContentText(message)
|
||||
.setPriority(Notification.PRIORITY_HIGH);
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
|
||||
|
||||
// Creates an explicit intent for an Activity in your app
|
||||
Intent intent = new Intent(this, AcceptActivity.class);
|
||||
|
@ -571,8 +589,8 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
|
||||
PendingIntent resultPendingIntent =
|
||||
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
builder.setContentIntent(resultPendingIntent);
|
||||
builder.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
|
||||
|
||||
builder = builder.setContentIntent(resultPendingIntent);
|
||||
|
||||
NotificationManager mNotificationManager =
|
||||
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
|
|
Loading…
Reference in a new issue