Skip to content

Instantly share code, notes, and snippets.

@iqzmn
Created October 31, 2019 12:13
Show Gist options
  • Select an option

  • Save iqzmn/f993dbdc6367d1d0d97de31305a9d2de to your computer and use it in GitHub Desktop.

Select an option

Save iqzmn/f993dbdc6367d1d0d97de31305a9d2de to your computer and use it in GitHub Desktop.
NotificationCompat.Builder getNotificationBuilder()

31.10.2019, 14:49:45

//если версия андроид выше 8, то нужен канал
//также после этой версии не принято объявлять receiver от BroadcasatReceiver в манифесте, использовать JobScheduler
class Main{
private NotificationCompat.Builder getNotificationBuilder() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
        return new NotificationCompat.Builder(this);
 		else {
        String channelId = "my_channel_id";
			 if (manager.getNotificationChannel(channelId) == null) {
									NotificationChannel channel = new NotificationChannel(channelId, "Text for user", NotificationManager.IMPORTANCE_LOW);
									manager.createNotificationChannel(channel);
				}
			return new NotificationCompat.Builder(this, channelId);
  	}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment