Search in sources :

Example 16 with NotificationChannel

use of android.app.NotificationChannel in project xDrip-plus by jamorham.

the class NotificationChannels method isSoundDifferent.

@TargetApi(26)
public static boolean isSoundDifferent(String id, NotificationChannel x) {
    // this does not have a sound
    if (x.getSound() == null)
        return false;
    final NotificationChannel c = getNotifManager().getNotificationChannel(id);
    // no channel with this id
    if (c == null)
        return false;
    if (c.getSound() == null)
        // this maybe will only happen if user disables sound so lets not create a new one in that case
        return false;
    final String original_sound = PersistentStore.getString("original-channel-sound-" + id);
    if (original_sound.equals("")) {
        PersistentStore.setString("original-channel-sound-" + id, x.getSound().toString());
        // no existing record so save the original and do nothing else
        return false;
    }
    if (original_sound.equals(x.getSound().toString()))
        // its the same sound still
        return false;
    // the sound has changed vs the original
    return true;
}
Also used : NotificationChannel(android.app.NotificationChannel) TargetApi(android.annotation.TargetApi)

Example 17 with NotificationChannel

use of android.app.NotificationChannel in project xDrip-plus by jamorham.

the class NotificationChannels method getChan.

@TargetApi(26)
public static NotificationChannel getChan(NotificationCompat.Builder wip) {
    final Notification temp = wip.build();
    if (temp.getChannelId() == null)
        return null;
    // create generic audio attributes
    final AudioAttributes generic_audio = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN).build();
    // create notification channel for hashing purposes from the existing notification builder
    NotificationChannel template = new NotificationChannel(temp.getChannelId(), getString(temp.getChannelId()), NotificationManager.IMPORTANCE_DEFAULT);
    // mirror the notification parameters in the channel
    template.setGroup(temp.getChannelId());
    template.setVibrationPattern(wip.mNotification.vibrate);
    template.setSound(wip.mNotification.sound, generic_audio);
    template.setLightColor(wip.mNotification.ledARGB);
    if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0))
        // weird how this doesn't work like vibration pattern
        template.enableLights(true);
    template.setDescription(temp.getChannelId() + " " + wip.hashCode());
    // get a nice string to identify the hash
    final String mhash = my_text_hash(template);
    // create another notification channel using the hash because id is immutable
    final NotificationChannel channel = new NotificationChannel(template.getId() + mhash, getString(temp.getChannelId()) + mhash, NotificationManager.IMPORTANCE_DEFAULT);
    // mirror the settings from the previous channel
    channel.setSound(template.getSound(), generic_audio);
    channel.setGroup(template.getGroup());
    channel.setDescription(template.getDescription());
    channel.setVibrationPattern(template.getVibrationPattern());
    template.setLightColor(wip.mNotification.ledARGB);
    if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0))
        // weird how this doesn't work like vibration pattern
        template.enableLights(true);
    template.setDescription(temp.getChannelId() + " " + wip.hashCode());
    // create a group to hold this channel if one doesn't exist or update text
    getNotifManager().createNotificationChannelGroup(new NotificationChannelGroup(channel.getGroup(), getString(channel.getGroup())));
    // create this channel if it doesn't exist or update text
    getNotifManager().createNotificationChannel(channel);
    return channel;
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) AudioAttributes(android.media.AudioAttributes) Notification(android.app.Notification) TargetApi(android.annotation.TargetApi)

Example 18 with NotificationChannel

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

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

use of android.app.NotificationChannel in project KeePassDX by Kunzisoft.

the class NotificationCopyingService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    clipboardHelper = new ClipboardHelper(this);
    // Create notification channel for Oreo+
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID_COPYING, CHANNEL_NAME_COPYING, NotificationManager.IMPORTANCE_LOW);
        notificationManager.createNotificationChannel(channel);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) ClipboardHelper(com.keepassdroid.timeout.ClipboardHelper)

Example 20 with NotificationChannel

use of android.app.NotificationChannel in project TrekAdvisor by peterLaurence.

the class LocationService method onStartCommand.

/**
 * Called when the service is started.
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    Notification.Builder notificationBuilder = new Notification.Builder(getApplicationContext()).setContentTitle(getText(R.string.app_name)).setContentText(getText(R.string.service_action)).setSmallIcon(R.mipmap.ic_launcher).setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)).setContentIntent(pendingIntent).setOngoing(true);
    if (android.os.Build.VERSION.SDK_INT >= 26) {
        /* This is only needed on Devices on Android O and above */
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel mChannel = new NotificationChannel(NOTIFICATION_ID, getText(R.string.service_description), NotificationManager.IMPORTANCE_DEFAULT);
        mChannel.enableLights(true);
        mChannel.setLightColor(Color.MAGENTA);
        if (notificationManager != null) {
            notificationManager.createNotificationChannel(mChannel);
        }
        notificationBuilder.setChannelId(NOTIFICATION_ID);
    }
    Notification notification = notificationBuilder.build();
    startForeground(SERVICE_ID, notification);
    mStarted = true;
    sendStatus();
    return START_NOT_STICKY;
}
Also used : NotificationChannel(android.app.NotificationChannel) Bitmap(android.graphics.Bitmap) NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) 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