Search in sources :

Example 31 with NotificationChannel

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

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

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

the class AppNotificationSettings method populateChannelList.

private void populateChannelList() {
    if (!mChannelGroups.isEmpty()) {
        // If there's anything in mChannelGroups, we've called populateChannelList twice.
        // Clear out existing channels and log.
        Log.w(TAG, "Notification channel group posted twice to settings - old size " + mChannelGroups.size() + ", new size " + mChannelGroupList.size());
        for (Preference p : mChannelGroups) {
            getPreferenceScreen().removePreference(p);
        }
    }
    if (mChannelGroupList.isEmpty()) {
        PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
        groupCategory.setTitle(R.string.notification_channels);
        groupCategory.setKey(KEY_GENERAL_CATEGORY);
        getPreferenceScreen().addPreference(groupCategory);
        mChannelGroups.add(groupCategory);
        Preference empty = new Preference(getPrefContext());
        empty.setTitle(R.string.no_channels);
        empty.setEnabled(false);
        groupCategory.addPreference(empty);
    } else {
        for (NotificationChannelGroup group : mChannelGroupList) {
            PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
            if (group.getId() == null) {
                groupCategory.setTitle(mChannelGroupList.size() > 1 ? R.string.notification_channels_other : R.string.notification_channels);
                groupCategory.setKey(KEY_GENERAL_CATEGORY);
            } else {
                groupCategory.setTitle(group.getName());
                groupCategory.setKey(group.getId());
            }
            groupCategory.setOrderingAsAdded(true);
            getPreferenceScreen().addPreference(groupCategory);
            mChannelGroups.add(groupCategory);
            final List<NotificationChannel> channels = group.getChannels();
            Collections.sort(channels, mChannelComparator);
            int N = channels.size();
            for (int i = 0; i < N; i++) {
                final NotificationChannel channel = channels.get(i);
                populateSingleChannelPrefs(groupCategory, channel);
            }
        }
        int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
        if (deletedChannelCount > 0 && getPreferenceScreen().findPreference(KEY_DELETED) == null) {
            mDeletedChannels = new FooterPreference(getPrefContext());
            mDeletedChannels.setSelectable(false);
            mDeletedChannels.setTitle(getResources().getQuantityString(R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
            mDeletedChannels.setEnabled(false);
            mDeletedChannels.setKey(KEY_DELETED);
            mDeletedChannels.setOrder(ORDER_LAST);
            getPreferenceScreen().addPreference(mDeletedChannels);
        }
    }
    updateDependents(mAppRow.banned);
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) LayoutPreference(com.android.settings.applications.LayoutPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) FooterPreference(com.android.settingslib.widget.FooterPreference) Preference(android.support.v7.preference.Preference) PreferenceCategory(android.support.v7.preference.PreferenceCategory) FooterPreference(com.android.settingslib.widget.FooterPreference)

Example 33 with NotificationChannel

use of android.app.NotificationChannel in project AndroidDevMetrics by frogermcs.

the class AndroidDevMetrics method showNotification.

private void showNotification() {
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        int importance = NotificationManager.IMPORTANCE_HIGH;
        String notificationChannel = "AndroidDevMetrics";
        NotificationChannel mChannel = mNotificationManager.getNotificationChannel(notificationChannel);
        if (mChannel == null) {
            mChannel = new NotificationChannel(notificationChannel, notificationChannel, importance);
            mChannel.setDescription(notificationChannel);
            mChannel.enableVibration(true);
            mChannel.setVibrationPattern(new long[] { 100, 200, 300, 400, 500, 400, 300, 200, 400 });
            mNotificationManager.createNotificationChannel(mChannel);
        }
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, notificationChannel).setSmallIcon(R.drawable.ic_timeline_white_18dp).setContentTitle(context.getString(R.string.adm_name)).setContentText("Click to see current metrics").setAutoCancel(autoCancelNotification);
        Intent resultIntent = new Intent(context, MetricsActivity.class);
        PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        mNotificationManager.notify("AndroidDevMetrics".hashCode(), mBuilder.build());
    } else {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_timeline_white_18dp).setContentTitle(context.getString(R.string.adm_name)).setContentText("Click to see current metrics").setAutoCancel(autoCancelNotification);
        Intent resultIntent = new Intent(context, MetricsActivity.class);
        PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        mNotificationManager.notify("AndroidDevMetrics".hashCode(), 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 34 with NotificationChannel

use of android.app.NotificationChannel in project PhoneProfiles by henrichg.

the class PPApplication method createGrantPermissionNotificationChannel.

static void createGrantPermissionNotificationChannel(Context context) {
    if (Build.VERSION.SDK_INT >= 26) {
        // The user-visible name of the channel.
        CharSequence name = context.getString(R.string.notification_channel_grant_permission);
        // The user-visible description of the channel.
        String description = context.getString(R.string.notification_channel_grant_permission_description);
        NotificationChannel channel = new NotificationChannel(GRANT_PERMISSION_NOTIFICATION_CHANNEL, name, NotificationManager.IMPORTANCE_DEFAULT);
        // Configure the notification channel.
        // channel.setImportance(importance);
        channel.setDescription(description);
        channel.enableLights(false);
        // Sets the notification light color for notifications posted to this
        // channel, if the device supports this feature.
        // channel.setLightColor(Color.RED);
        channel.enableVibration(false);
        // channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager != null)
            notificationManager.createNotificationChannel(channel);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager)

Example 35 with NotificationChannel

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

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)

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