1 /* 2 * Copyright (C) 2022 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.os.UserHandle; 27 import android.provider.Settings; 28 import android.text.TextUtils; 29 30 import com.android.nfc.R; 31 32 /** 33 * This class handles the Notification Manager for the nfc developer setting notification 34 */ 35 36 public class NfcDeveloperOptionNotification { 37 private static final String NFC_NOTIFICATION_CHANNEL = "nfc_logging_channel"; 38 private NotificationChannel mNotificationChannel; 39 public static final int NOTIFICATION_ID_NFC = -1000002; 40 Context mContext; 41 42 /** 43 * Constructor 44 * 45 * @param ctx The context to use to obtain access to the resources 46 */ NfcDeveloperOptionNotification(Context ctx)47 public NfcDeveloperOptionNotification(Context ctx) { 48 mContext = ctx; 49 } 50 51 /** 52 * Start the notification. 53 */ startNotification()54 public void startNotification() { 55 Intent settingIntent; 56 // Go to developer option after user click the notification 57 settingIntent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); 58 settingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 59 60 Notification.Builder builder = new Notification.Builder(mContext, NFC_NOTIFICATION_CHANNEL); 61 builder.setContentTitle(mContext.getString(R.string.nfc_logging_alert_title)) 62 .setContentText(mContext.getString(R.string.nfc_logging_alert_message)) 63 .setSmallIcon(android.R.drawable.stat_sys_warning) 64 .setPriority(NotificationManager.IMPORTANCE_HIGH) 65 .setOngoing(true) 66 .setAutoCancel(false) 67 .setContentIntent(PendingIntent.getActivity(mContext, 0, settingIntent, 68 PendingIntent.FLAG_IMMUTABLE)); 69 mNotificationChannel = new NotificationChannel(NFC_NOTIFICATION_CHANNEL, 70 mContext.getString(R.string.nfcUserLabel), NotificationManager.IMPORTANCE_DEFAULT); 71 NotificationManager notificationManager = 72 mContext.getSystemService(NotificationManager.class); 73 notificationManager.createNotificationChannel(mNotificationChannel); 74 notificationManager.notify(NOTIFICATION_ID_NFC, builder.build()); 75 } 76 } 77 78