Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/backend/Notifications.java
- This file was added.
package it.reyboz.bustorino.backend; | |||||
import android.app.NotificationChannel; | |||||
import android.app.NotificationManager; | |||||
import android.content.Context; | |||||
import android.os.Build; | |||||
import it.reyboz.bustorino.R; | |||||
public class Notifications { | |||||
public static final String DEFAULT_CHANNEL_ID ="Default"; | |||||
public static void createDefaultNotificationChannel(Context context) { | |||||
// Create the NotificationChannel, but only on API 26+ because | |||||
// the NotificationChannel class is new and not in the support library | |||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |||||
CharSequence name = context.getString(R.string.default_notification_channel); | |||||
String description = context.getString(R.string.default_notification_channel_description); | |||||
int importance = NotificationManager.IMPORTANCE_DEFAULT; | |||||
NotificationChannel channel = new NotificationChannel(DEFAULT_CHANNEL_ID, name, importance); | |||||
channel.setDescription(description); | |||||
// Register the channel with the system; you can't change the importance | |||||
// or other notification behaviors after this | |||||
NotificationManager notificationManager = context.getSystemService(NotificationManager.class); | |||||
notificationManager.createNotificationChannel(channel); | |||||
} | |||||
} | |||||
/** | |||||
* Register a notification channel on Android Oreo and above | |||||
* @param con a Context | |||||
* @param name channel name | |||||
* @param description channel description | |||||
* @param importance channel importance (from NotificationManager) | |||||
* @param ID channel ID | |||||
*/ | |||||
public static void createNotificationChannel(Context con, String name, String description, int importance, String ID){ | |||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |||||
NotificationChannel channel = new NotificationChannel(ID, name, importance); | |||||
channel.setDescription(description); | |||||
// Register the channel with the system; you can't change the importance | |||||
// or other notification behaviors after this | |||||
NotificationManager notificationManager = con.getSystemService(NotificationManager.class); | |||||
notificationManager.createNotificationChannel(channel); | |||||
} | |||||
} | |||||
} |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register