diff options
author | fionaxu <fionaxu@google.com> | 2017-04-04 14:13:11 -0700 |
---|---|---|
committer | fionaxu <fionaxu@google.com> | 2017-04-04 17:05:47 -0700 |
commit | 009848b03ed049bd9f6f6e8a9fb4e7da414727a0 (patch) | |
tree | 4e81637b95776ced8fa936c2a64660ade5930253 /packages/CarrierDefaultApp/src | |
parent | 2ac969827115c1b8bc86d9017eb1c7c1d5421b10 (diff) |
support notification channel for defaultcarrier app
Apps posting notifications for O must supply a notification channel for
all notifications
Bug: 36895752
Change-Id: I7ec3b4cd8a6ea05c3ca9316d1f79b56e3531f5d0
Diffstat (limited to 'packages/CarrierDefaultApp/src')
-rw-r--r-- | packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/CarrierActionUtils.java | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/CarrierActionUtils.java b/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/CarrierActionUtils.java index 73ff3a9b5d1e..7fd16019267e 100644 --- a/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/CarrierActionUtils.java +++ b/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/CarrierActionUtils.java @@ -16,6 +16,7 @@ package com.android.carrierdefaultapp; import android.app.Notification; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; @@ -35,6 +36,7 @@ public class CarrierActionUtils { private static final String PORTAL_NOTIFICATION_TAG = "CarrierDefault.Portal.Notification"; private static final String NO_DATA_NOTIFICATION_TAG = "CarrierDefault.NoData.Notification"; + private static final String NOTIFICATION_CHANNEL_ID_MOBILE_DATA_STATUS = "mobile_data_status"; private static final int PORTAL_NOTIFICATION_ID = 0; private static final int NO_DATA_NOTIFICATION_ID = 1; private static boolean ENABLE = true; @@ -150,9 +152,18 @@ public class CarrierActionUtils { private static Notification getNotification(Context context, int titleId, int textId, PendingIntent pendingIntent) { final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class); + final NotificationManager notificationManager = context.getSystemService( + NotificationManager.class); final Resources resources = context.getResources(); final Bundle extras = Bundle.forPair(Notification.EXTRA_SUBSTITUTE_APP_NAME, resources.getString(R.string.android_system_label)); + /* Creates the notification channel and registers it with NotificationManager. If a channel + * with the same ID is already registered, NotificationManager will ignore this call. + */ + notificationManager.createNotificationChannel(new NotificationChannel( + NOTIFICATION_CHANNEL_ID_MOBILE_DATA_STATUS, + resources.getString(R.string.mobile_data_status_notification_channel_name), + NotificationManager.IMPORTANCE_DEFAULT)); Notification.Builder builder = new Notification.Builder(context) .setContentTitle(resources.getString(titleId)) .setContentText(String.format(resources.getString(textId), @@ -167,7 +178,8 @@ public class CarrierActionUtils { .setLocalOnly(true) .setWhen(System.currentTimeMillis()) .setShowWhen(false) - .setExtras(extras); + .setExtras(extras) + .setChannel(NOTIFICATION_CHANNEL_ID_MOBILE_DATA_STATUS); if (pendingIntent != null) { builder.setContentIntent(pendingIntent); |