Search in sources :

Example 71 with NotificationChannel

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;
}
Also used : NotificationChannel(android.app.NotificationChannel)

Example 72 with NotificationChannel

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);
        }
    }
}
Also used : JobScheduler(android.app.job.JobScheduler) NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.app.TaskStackBuilder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ClearIdentityService(org.ea.sqrl.services.ClearIdentityService) NotificationChannel(android.app.NotificationChannel) JobInfo(android.app.job.JobInfo) NotificationCompat(android.support.v4.app.NotificationCompat) AlarmManager(android.app.AlarmManager) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder)

Example 73 with NotificationChannel

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);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel)

Example 74 with NotificationChannel

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);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) SuppressLint(android.annotation.SuppressLint)

Example 75 with NotificationChannel

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;
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager)

Aggregations

NotificationChannel (android.app.NotificationChannel)762 Test (org.junit.Test)430 NotificationBackend (com.android.settings.notification.NotificationBackend)215 NotificationManager (android.app.NotificationManager)210 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)114 Intent (android.content.Intent)87 Preference (androidx.preference.Preference)76 PendingIntent (android.app.PendingIntent)73 NotificationChannelGroup (android.app.NotificationChannelGroup)54 NotificationCompat (android.support.v4.app.NotificationCompat)45 Notification (android.app.Notification)43 ArrayList (java.util.ArrayList)34 TargetApi (android.annotation.TargetApi)32 AudioAttributes (android.media.AudioAttributes)31 RequiresApi (android.support.annotation.RequiresApi)28 RequiresApi (androidx.annotation.RequiresApi)25 Uri (android.net.Uri)21 RestrictedListPreference (com.android.settings.RestrictedListPreference)20 SuppressLint (android.annotation.SuppressLint)19 ShortcutInfo (android.content.pm.ShortcutInfo)19