Search in sources :

Example 41 with NotificationChannel

use of android.app.NotificationChannel in project Sprog-App by PaulKlinger.

the class SprogApplication method createNotificationChannel.

private void createNotificationChannel() {
    if (Build.VERSION.SDK_INT >= 26) {
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel poemChannel = new NotificationChannel("poem_channel", "Sprog Poems", NotificationManager.IMPORTANCE_LOW);
        poemChannel.setDescription("Poem for your Sprog");
        poemChannel.enableLights(true);
        poemChannel.setLightColor(Color.GREEN);
        poemChannel.enableVibration(false);
        mNotificationManager.createNotificationChannel(poemChannel);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager)

Example 42 with NotificationChannel

use of android.app.NotificationChannel in project react-native-twilio-programmable-voice by hoxfon.

the class CallNotificationManager method initCallNotificationsChannel.

public void initCallNotificationsChannel(NotificationManager notificationManager) {
    if (Build.VERSION.SDK_INT < 26) {
        return;
    }
    NotificationChannel channel = new NotificationChannel(VOICE_CHANNEL, "Primary Voice Channel", NotificationManager.IMPORTANCE_DEFAULT);
    channel.setLightColor(Color.GREEN);
    channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    notificationManager.createNotificationChannel(channel);
}
Also used : NotificationChannel(android.app.NotificationChannel)

Example 43 with NotificationChannel

use of android.app.NotificationChannel in project NetGuard by M66B.

the class ApplicationEx method createNotificationChannels.

@TargetApi(Build.VERSION_CODES.O)
private void createNotificationChannels() {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationChannel foreground = new NotificationChannel("foreground", getString(R.string.channel_foreground), NotificationManager.IMPORTANCE_MIN);
    foreground.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
    nm.createNotificationChannel(foreground);
    NotificationChannel notify = new NotificationChannel("notify", getString(R.string.channel_notify), NotificationManager.IMPORTANCE_DEFAULT);
    notify.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
    nm.createNotificationChannel(notify);
    NotificationChannel access = new NotificationChannel("access", getString(R.string.channel_access), NotificationManager.IMPORTANCE_DEFAULT);
    access.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
    nm.createNotificationChannel(access);
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) TargetApi(android.annotation.TargetApi)

Example 44 with NotificationChannel

use of android.app.NotificationChannel in project platform_packages_apps_Settings by BlissRoms.

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 45 with NotificationChannel

use of android.app.NotificationChannel in project platform_packages_apps_Settings by BlissRoms.

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)

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