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;
}
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;
}
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);
}
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);
}
}
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;
}
Aggregations