Merge "support notification channel for defaultcarrier app" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ff16d749dd
@@ -6,6 +6,7 @@
|
||||
<string name="no_data_notification_id">Your mobile data has been deactivated</string>
|
||||
<string name="portal_notification_detail">Tap to visit the %s website</string>
|
||||
<string name="no_data_notification_detail">Please contact your service provider %s</string>
|
||||
<string name="mobile_data_status_notification_channel_name">Mobile data status</string>
|
||||
<string name="action_bar_label">Sign in to mobile network</string>
|
||||
<string name="ssl_error_warning">The network you’re trying to join has security issues.</string>
|
||||
<string name="ssl_error_example">For example, the login page may not belong to the organization shown.</string>
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user