summaryrefslogtreecommitdiff
path: root/src/com/android/nfc/NfcBlockedNotification.java
blob: 83d02bbbfc4a1a2b0762a41073c90f0c7378ded1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.nfc;

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.net.Uri;
import android.text.TextUtils;

/**
 * This class handles the Notification Manager for the antenna blocked notification
 */

public class NfcBlockedNotification {
    private static final String NFC_NOTIFICATION_CHANNEL = "nfc_notification_channel";
    private NotificationChannel mNotificationChannel;
    public static final int NOTIFICATION_ID_NFC = -1000001;
    Context mContext;

    /**
     * Constructor
     *
     * @param ctx The context to use to obtain access to the resources
     */
    public NfcBlockedNotification(Context ctx) {
        mContext = ctx;
    }

    /**
     * Start the notification.
     */
    public void startNotification() {
        Intent infoIntent;
        if (TextUtils.isEmpty(mContext.getString(R.string.antenna_blocked_alert_link))) {
            // Do nothing after user click the notification if antenna_blocked_alert_link is empty
            infoIntent = new Intent();
        } else {
            // Open the link after user click the notification
            infoIntent = new Intent(Intent.ACTION_VIEW);
            infoIntent.setData(Uri.parse(mContext.getString(R.string.antenna_blocked_alert_link)));
        }
        Notification.Builder builder = new Notification.Builder(mContext, NFC_NOTIFICATION_CHANNEL);
        builder.setContentTitle(mContext.getString(R.string.nfc_blocking_alert_title))
                .setContentText(mContext.getString(R.string.nfc_blocking_alert_message))
                .setSmallIcon(android.R.drawable.stat_sys_warning)
                .setPriority(NotificationManager.IMPORTANCE_DEFAULT)
                .setAutoCancel(true)
                .setContentIntent(PendingIntent.getActivity(mContext, 0, infoIntent,
                      PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE));
        mNotificationChannel = new NotificationChannel(NFC_NOTIFICATION_CHANNEL,
                mContext.getString(R.string.nfcUserLabel), NotificationManager.IMPORTANCE_DEFAULT);
        NotificationManager notificationManager =
                mContext.getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(mNotificationChannel);
        notificationManager.notify(NOTIFICATION_ID_NFC, builder.build());
    }
}