Merge pull request #2241 from dlvoy/hotfix/2240_wear_notiffication_channel
(#2240) Fixed open loop notifications on wear os - support for Androi…
This commit is contained in:
commit
d4fc8492da
|
@ -1,24 +1,22 @@
|
||||||
package info.nightscout.androidaps.data;
|
package info.nightscout.androidaps.data;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
||||||
import androidx.core.app.NotificationCompat;
|
|
||||||
import androidx.core.app.NotificationManagerCompat;
|
|
||||||
|
|
||||||
import android.util.Log;
|
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.ConnectionResult;
|
||||||
import com.google.android.gms.common.api.GoogleApiClient;
|
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.Wearable;
|
||||||
import com.google.android.gms.wearable.WearableListenerService;
|
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.R;
|
||||||
|
import info.nightscout.androidaps.interaction.AAPSPreferences;
|
||||||
import info.nightscout.androidaps.interaction.actions.AcceptActivity;
|
import info.nightscout.androidaps.interaction.actions.AcceptActivity;
|
||||||
import info.nightscout.androidaps.interaction.actions.CPPActivity;
|
import info.nightscout.androidaps.interaction.actions.CPPActivity;
|
||||||
import info.nightscout.androidaps.interaction.utils.Persistence;
|
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 ACTION_RESEND_BULK = "com.dexdrip.stephenblack.nightwatch.RESEND_BULK_DATA";
|
||||||
|
private static final String AAPS_NOTIFY_CHANNEL_ID = "AndroidAPS-Openloop";
|
||||||
|
|
||||||
GoogleApiClient googleApiClient;
|
GoogleApiClient googleApiClient;
|
||||||
private long lastRequest = 0;
|
private long lastRequest = 0;
|
||||||
|
@ -552,13 +554,29 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyChangeRequest(String title, String message, String actionstring) {
|
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 =
|
// Register the channel with the system; you can't change the importance
|
||||||
new Notification.Builder(this); //,"AndroidAPS-Openloop");
|
// or other notification behaviors after this
|
||||||
builder.setSmallIcon(R.drawable.notif_icon)
|
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)
|
.setContentTitle(title)
|
||||||
.setContentText(message)
|
.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
|
// Creates an explicit intent for an Activity in your app
|
||||||
Intent intent = new Intent(this, AcceptActivity.class);
|
Intent intent = new Intent(this, AcceptActivity.class);
|
||||||
|
@ -571,8 +589,8 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
|
|
||||||
PendingIntent resultPendingIntent =
|
PendingIntent resultPendingIntent =
|
||||||
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
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 mNotificationManager =
|
||||||
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
|
Loading…
Reference in a new issue