use of android.app.NotificationChannel in project MusicLake by caiyonglong.
the class MusicPlayerService method initChannelId.
/**
* 创建Notification ChannelID
*
* @return
*/
private String initChannelId() {
// 通知渠道的id
String id = "music_lake_01";
// 用户可以看到的通知渠道的名字.
CharSequence name = "音乐湖";
// 用户可以看到的通知渠道的描述
String description = "通知栏播放控制";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel mChannel = null;
mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
mChannel.enableLights(false);
mChannel.enableVibration(false);
// 最后在notificationmanager中创建该通知渠道
mNotificationManager.createNotificationChannel(mChannel);
}
return id;
}
use of android.app.NotificationChannel in project secure-quick-reliable-login by kalaspuffar.
the class LoginBaseActivity method showClearNotification.
public void showClearNotification() {
final String CHANNEL_ID = "sqrl_notify_01";
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, "SQRL Notification Channel", NotificationManager.IMPORTANCE_DEFAULT);
notificationChannel.enableVibration(false);
notificationChannel.enableLights(false);
notificationChannel.setSound(null, null);
notificationManager.createNotificationChannel(notificationChannel);
}
long[] v = {};
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID).setSmallIcon(R.drawable.ic_stat_sqrl_logo_vector_outline).setContentTitle(getString(R.string.notification_identity_unlocked)).setContentText(getString(R.string.notification_identity_unlocked_title)).setAutoCancel(true).setVibrate(v).setSound(null).setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.notification_identity_unlocked_desc)));
Intent resultIntent = new Intent(this, ClearIdentityActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ClearIdentityActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_IDENTITY_UNLOCKED, mBuilder.build());
long delayMillis = SQRLStorage.getInstance().getIdleTimeout() * 60000;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
JobInfo jobInfo = new JobInfo.Builder(ClearIdentityService.JOB_NUMBER, new ComponentName(this, ClearIdentityService.class)).setMinimumLatency(delayMillis).build();
JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(jobInfo);
} else {
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(getApplicationContext(), ClearIdentityReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
int SDK_INT = Build.VERSION.SDK_INT;
long timeInMillis = System.currentTimeMillis() + delayMillis;
if (SDK_INT < Build.VERSION_CODES.KITKAT) {
alarmManager.set(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
} else if (SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
}
}
}
use of android.app.NotificationChannel in project Remindy by abicelis.
the class NotificationUtil method createNotificationChannel.
// Needed for Android 8 Oreo +
private static void createNotificationChannel(NotificationManager notificationManager, @NonNull String channelId, String channelName, String channelDescription) {
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
channel.setDescription(channelDescription);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
notificationManager.createNotificationChannel(channel);
}
}
use of android.app.NotificationChannel in project Timber by naman14.
the class MusicService method createNotificationChannel.
private void createNotificationChannel() {
if (TimberUtils.isOreo()) {
CharSequence name = "Timber";
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
manager.createNotificationChannel(mChannel);
}
}
use of android.app.NotificationChannel in project Tusky by Vavassor.
the class NotificationHelper method filterNotification.
private static boolean filterNotification(AccountEntity account, Notification notification, Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = getChannelId(account, notification);
if (channelId == null) {
// unknown notificationtype
return false;
}
// noinspection ConstantConditions
NotificationChannel channel = notificationManager.getNotificationChannel(channelId);
return channel.getImportance() > NotificationManager.IMPORTANCE_NONE;
}
switch(notification.getType()) {
case MENTION:
return account.getNotificationsMentioned();
case STATUS:
return account.getNotificationsSubscriptions();
case FOLLOW:
return account.getNotificationsFollowed();
case FOLLOW_REQUEST:
return account.getNotificationsFollowRequested();
case REBLOG:
return account.getNotificationsReblogged();
case FAVOURITE:
return account.getNotificationsFavorited();
case POLL:
return account.getNotificationsPolls();
default:
return false;
}
}
Aggregations