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.Activity; 20 import android.app.Notification; 21 import android.app.NotificationChannel; 22 import android.app.NotificationManager; 23 import android.app.PendingIntent; 24 import android.content.Context; 25 import android.content.DialogInterface; 26 import android.content.Intent; 27 import android.content.IntentFilter; 28 import android.content.res.Resources; 29 import android.net.Uri; 30 import android.os.Bundle; 31 import android.text.TextUtils; 32 import com.android.nfc.R; 33 34 public class NfcBlockedNotification extends Activity { 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 @Override onCreate(Bundle savedInstanceState)39 protected void onCreate(Bundle savedInstanceState) { 40 super.onCreate(savedInstanceState); 41 PendingIntent pIntent; 42 Intent infoIntent; 43 if (TextUtils.isEmpty(getString(R.string.antenna_blocked_alert_link))) { 44 // Do nothing after user click the notification if antenna_blocked_alert_link is empty 45 infoIntent = new Intent(); 46 } else { 47 // Open the link after user click the notification 48 infoIntent = new Intent(Intent.ACTION_VIEW); 49 infoIntent.setData(Uri.parse(getString(R.string.antenna_blocked_alert_link))); 50 } 51 Notification.Builder builder = new Notification.Builder(this, NFC_NOTIFICATION_CHANNEL); 52 builder.setContentTitle(getString(R.string.nfc_blocking_alert_title)) 53 .setContentText(getString(R.string.nfc_blocking_alert_message)) 54 .setSmallIcon(android.R.drawable.stat_sys_warning) 55 .setPriority(NotificationManager.IMPORTANCE_DEFAULT) 56 .setAutoCancel(true) 57 .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, infoIntent, 0)); 58 mNotificationChannel = new NotificationChannel(NFC_NOTIFICATION_CHANNEL, 59 getString(R.string.nfcUserLabel), NotificationManager.IMPORTANCE_DEFAULT); 60 NotificationManager notificationManager = 61 getApplicationContext().getSystemService(NotificationManager.class); 62 notificationManager.createNotificationChannel(mNotificationChannel); 63 notificationManager.notify(NOTIFICATION_ID_NFC, builder.build()); 64 } 65 } 66 67