Search in sources :

Example 21 with NotificationChannel

use of android.app.NotificationChannel in project packages_apps_ResurrectionOTA by ResurrectionRemix.

the class CheckUpdateTask method showNotification.

private void showNotification(Context context) {
    if (mIsBackgroundThread) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        int notifyID = 1;
        String id = "resurrectionota_channel";
        CharSequence name = context.getString(R.string.resurrection_channel);
        String description = context.getString(R.string.resurrection_channel_description);
        int importance = NotificationManager.IMPORTANCE_LOW;
        NotificationChannel mChannel = new NotificationChannel(id, name, importance);
        mChannel.setDescription(description);
        notificationManager.createNotificationChannel(mChannel);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context.getApplicationContext()).setSmallIcon(R.drawable.ic_notification_resurrection).setContentTitle(context.getString(R.string.notification_title)).setContentText(context.getString(R.string.notification_message)).setOnlyAlertOnce(true).setAutoCancel(true).setChannelId(id);
        Intent intent = new Intent(context, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        mBuilder.setContentIntent(pendingIntent);
        notificationManager.notify(notifyID, mBuilder.build());
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 22 with NotificationChannel

use of android.app.NotificationChannel in project android_packages_apps_Settings by crdroidandroid.

the class SimSelectNotification method createNotification.

private void createNotification(Context context) {
    final Resources resources = context.getResources();
    NotificationChannel notificationChannel = new NotificationChannel(SIM_SELECT_NOTIFICATION_CHANNEL, resources.getString(R.string.sim_selection_channel_title), NotificationManager.IMPORTANCE_LOW);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, SIM_SELECT_NOTIFICATION_CHANNEL).setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp).setColor(context.getColor(R.color.sim_noitification)).setContentTitle(resources.getString(R.string.sim_notification_title)).setContentText(resources.getString(R.string.sim_notification_summary));
    Intent resultIntent = new Intent(context, SimSettingsActivity.class);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.createNotificationChannel(notificationChannel);
    notificationManager.notify(NOTIFICATION_ID, builder.build());
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent)

Example 23 with NotificationChannel

use of android.app.NotificationChannel in project android_packages_apps_Settings by SudaMod.

the class BluetoothPairingService method onCreate.

@Override
public void onCreate() {
    NotificationManager mgr = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationChannel notificationChannel = new NotificationChannel(BLUETOOTH_NOTIFICATION_CHANNEL, this.getString(R.string.bluetooth), NotificationManager.IMPORTANCE_HIGH);
    mgr.createNotificationChannel(notificationChannel);
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager)

Example 24 with NotificationChannel

use of android.app.NotificationChannel in project android_packages_apps_Settings by SudaMod.

the class BluetoothPermissionRequest method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    mContext = context;
    String action = intent.getAction();
    if (DEBUG)
        Log.d(TAG, "onReceive" + action);
    if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REQUEST)) {
        UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
        // skip the notification for managed profiles.
        if (um.isManagedProfile()) {
            if (DEBUG)
                Log.d(TAG, "Blocking notification for managed profile.");
            return;
        }
        // convert broadcast intent into activity intent (same action string)
        mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        mRequestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION);
        mReturnPackage = intent.getStringExtra(BluetoothDevice.EXTRA_PACKAGE_NAME);
        mReturnClass = intent.getStringExtra(BluetoothDevice.EXTRA_CLASS_NAME);
        if (DEBUG)
            Log.d(TAG, "onReceive request type: " + mRequestType + " return " + mReturnPackage + "," + mReturnClass);
        // dialog or notification.
        if (checkUserChoice()) {
            return;
        }
        Intent connectionAccessIntent = new Intent(action);
        connectionAccessIntent.setClass(context, BluetoothPermissionActivity.class);
        // We use the FLAG_ACTIVITY_MULTIPLE_TASK since we can have multiple concurrent access
        // requests.
        connectionAccessIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        // This is needed to create two pending intents to the same activity. The value is not
        // used in the activity.
        connectionAccessIntent.setType(Integer.toString(mRequestType));
        connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
        connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
        connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_PACKAGE_NAME, mReturnPackage);
        connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_CLASS_NAME, mReturnClass);
        String deviceAddress = mDevice != null ? mDevice.getAddress() : null;
        String deviceName = mDevice != null ? mDevice.getName() : null;
        String title = null;
        String message = null;
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (powerManager.isScreenOn() && LocalBluetoothPreferences.shouldShowDialogInForeground(context, deviceAddress, deviceName)) {
            context.startActivity(connectionAccessIntent);
        } else {
            // Put up a notification that leads to the dialog
            // Create an intent triggered by clicking on the
            // "Clear All Notifications" button
            Intent deleteIntent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY);
            deleteIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
            deleteIntent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT, BluetoothDevice.CONNECTION_ACCESS_NO);
            deleteIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
            String deviceAlias = Utils.createRemoteName(context, mDevice);
            switch(mRequestType) {
                case BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS:
                    title = context.getString(R.string.bluetooth_phonebook_request);
                    message = context.getString(R.string.bluetooth_pb_acceptance_dialog_text, deviceAlias, deviceAlias);
                    break;
                case BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS:
                    title = context.getString(R.string.bluetooth_map_request);
                    message = context.getString(R.string.bluetooth_map_acceptance_dialog_text, deviceAlias, deviceAlias);
                    break;
                case BluetoothDevice.REQUEST_TYPE_SIM_ACCESS:
                    title = context.getString(R.string.bluetooth_sap_request);
                    message = context.getString(R.string.bluetooth_sap_acceptance_dialog_text, deviceAlias, deviceAlias);
                    break;
                default:
                    title = context.getString(R.string.bluetooth_connection_permission_request);
                    message = context.getString(R.string.bluetooth_connection_dialog_text, deviceAlias, deviceAlias);
                    break;
            }
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            if (mNotificationChannel == null) {
                mNotificationChannel = new NotificationChannel(BLUETOOTH_NOTIFICATION_CHANNEL, context.getString(R.string.bluetooth), NotificationManager.IMPORTANCE_HIGH);
                notificationManager.createNotificationChannel(mNotificationChannel);
            }
            Notification notification = new Notification.Builder(context, BLUETOOTH_NOTIFICATION_CHANNEL).setContentTitle(title).setTicker(message).setContentText(message).setSmallIcon(android.R.drawable.stat_sys_data_bluetooth).setAutoCancel(true).setPriority(Notification.PRIORITY_MAX).setOnlyAlertOnce(false).setDefaults(Notification.DEFAULT_ALL).setContentIntent(PendingIntent.getActivity(context, 0, connectionAccessIntent, 0)).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setColor(context.getColor(com.android.internal.R.color.system_notification_accent_color)).setLocalOnly(true).build();
            // Cannot be set with the builder.
            notification.flags |= Notification.FLAG_NO_CLEAR;
            notificationManager.notify(getNotificationTag(mRequestType), NOTIFICATION_ID, notification);
        }
    } else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL)) {
        // Remove the notification
        NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mRequestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
        manager.cancel(getNotificationTag(mRequestType), NOTIFICATION_ID);
    }
}
Also used : PowerManager(android.os.PowerManager) NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) UserManager(android.os.UserManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 25 with NotificationChannel

use of android.app.NotificationChannel in project android_packages_apps_Settings by SudaMod.

the class SimSelectNotification method createNotification.

private void createNotification(Context context) {
    final Resources resources = context.getResources();
    NotificationChannel notificationChannel = new NotificationChannel(SIM_SELECT_NOTIFICATION_CHANNEL, resources.getString(R.string.sim_selection_channel_title), NotificationManager.IMPORTANCE_LOW);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, SIM_SELECT_NOTIFICATION_CHANNEL).setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp).setColor(context.getColor(R.color.sim_noitification)).setContentTitle(resources.getString(R.string.sim_notification_title)).setContentText(resources.getString(R.string.sim_notification_summary));
    Intent resultIntent = new Intent(context, SimSettingsActivity.class);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.createNotificationChannel(notificationChannel);
    notificationManager.notify(NOTIFICATION_ID, builder.build());
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent)

Aggregations

NotificationChannel (android.app.NotificationChannel)492 NotificationManager (android.app.NotificationManager)202 Test (org.junit.Test)180 Intent (android.content.Intent)73 PendingIntent (android.app.PendingIntent)68 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)59 NotificationCompat (android.support.v4.app.NotificationCompat)45 Notification (android.app.Notification)36 Preference (androidx.preference.Preference)33 TargetApi (android.annotation.TargetApi)30 NotificationChannelGroup (android.app.NotificationChannelGroup)30 RequiresApi (android.support.annotation.RequiresApi)29 AudioAttributes (android.media.AudioAttributes)24 RequiresApi (androidx.annotation.RequiresApi)20 SuppressLint (android.annotation.SuppressLint)19 Uri (android.net.Uri)19 ArrayList (java.util.ArrayList)15 RestrictedListPreference (com.android.settings.RestrictedListPreference)10 Context (android.content.Context)9 SharedPreferences (android.content.SharedPreferences)9