• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.nfc;
18 
19 import android.app.Notification;
20 import android.app.NotificationChannel;
21 import android.app.NotificationManager;
22 import android.app.PendingIntent;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.net.Uri;
26 import android.text.TextUtils;
27 
28 import com.android.nfc.R;
29 
30 /**
31  * This class handles the Notification Manager for the antenna blocked notification
32  */
33 
34 public class NfcBlockedNotification {
35     private static final String NFC_NOTIFICATION_CHANNEL = "nfc_notification_channel";
36     private NotificationChannel mNotificationChannel;
37     public static final int NOTIFICATION_ID_NFC = -1000001;
38     Context mContext;
39 
40     /**
41      * Constructor
42      *
43      * @param ctx The context to use to obtain access to the resources
44      */
NfcBlockedNotification(Context ctx)45     public NfcBlockedNotification(Context ctx) {
46         mContext = ctx;
47     }
48 
49     /**
50      * Start the notification.
51      */
startNotification()52     public void startNotification() {
53         Intent infoIntent;
54         if (TextUtils.isEmpty(mContext.getString(R.string.antenna_blocked_alert_link))) {
55             // Do nothing after user click the notification if antenna_blocked_alert_link is empty
56             infoIntent = new Intent();
57         } else {
58             // Open the link after user click the notification
59             infoIntent = new Intent(Intent.ACTION_VIEW);
60             infoIntent.setData(Uri.parse(mContext.getString(R.string.antenna_blocked_alert_link)));
61         }
62         Notification.Builder builder = new Notification.Builder(mContext, NFC_NOTIFICATION_CHANNEL);
63         builder.setContentTitle(mContext.getString(R.string.nfc_blocking_alert_title))
64                 .setContentText(mContext.getString(R.string.nfc_blocking_alert_message))
65                 .setSmallIcon(android.R.drawable.stat_sys_warning)
66                 .setPriority(NotificationManager.IMPORTANCE_DEFAULT)
67                 .setAutoCancel(true)
68                 .setContentIntent(PendingIntent.getActivity(mContext, 0, infoIntent,
69                       PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE));
70         mNotificationChannel = new NotificationChannel(NFC_NOTIFICATION_CHANNEL,
71                 mContext.getString(R.string.nfcUserLabel), NotificationManager.IMPORTANCE_DEFAULT);
72         NotificationManager notificationManager =
73                 mContext.getSystemService(NotificationManager.class);
74         notificationManager.createNotificationChannel(mNotificationChannel);
75         notificationManager.notify(NOTIFICATION_ID_NFC, builder.build());
76     }
77 }
78 
79