2020-06-19 17:40:18 -04:00
|
|
|
package ht.sr.git.whereswaldon.niotify;
|
|
|
|
|
2020-06-19 18:28:01 -04:00
|
|
|
import android.content.Context;
|
2020-06-19 17:40:18 -04:00
|
|
|
import android.app.Notification;
|
|
|
|
import android.app.NotificationChannel;
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.drawable.Icon;
|
|
|
|
|
|
|
|
public class NotificationHelper {
|
2020-06-19 18:35:55 -04:00
|
|
|
private final static String tag = "NotificationHelper";
|
|
|
|
public static void newChannel(Context ctx, String channelID, String name, String description) {
|
2020-06-19 18:28:01 -04:00
|
|
|
Log.w(tag,String.format("newChannel invoked"));
|
|
|
|
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
2020-06-19 18:35:55 -04:00
|
|
|
NotificationChannel channel = new NotificationChannel(channelID, name, importance);
|
2020-06-19 18:28:01 -04:00
|
|
|
Log.e(tag,String.format("channel: %s",channel));
|
|
|
|
channel.setDescription(description);
|
|
|
|
|
|
|
|
NotificationManager notificationManager = ctx.getSystemService(NotificationManager.class);
|
|
|
|
Log.e(tag,String.format("manager: %s",notificationManager));
|
|
|
|
notificationManager.createNotificationChannel(channel);
|
2020-06-19 17:40:18 -04:00
|
|
|
}
|
2020-06-19 19:07:37 -04:00
|
|
|
public static void sendNotification(Context ctx, String channelID, int notificationID, String title, String text) {
|
|
|
|
Notification.Builder builder = new Notification.Builder(ctx, channelID)
|
|
|
|
.setContentTitle(title)
|
|
|
|
.setSmallIcon(Icon.createWithBitmap(Bitmap.createBitmap(1,1,Bitmap.Config.ALPHA_8)))
|
|
|
|
.setContentText(text)
|
|
|
|
.setPriority(Notification.PRIORITY_DEFAULT);
|
|
|
|
|
|
|
|
NotificationManager notificationManager = ctx.getSystemService(NotificationManager.class);
|
|
|
|
notificationManager.notify(notificationID, builder.build());
|
|
|
|
}
|
2020-06-20 10:17:40 -04:00
|
|
|
public static void cancelNotification(Context ctx, int notificationID) {
|
|
|
|
NotificationManager notificationManager = ctx.getSystemService(NotificationManager.class);
|
|
|
|
notificationManager.cancel(notificationID);
|
|
|
|
}
|
2020-06-19 17:40:18 -04:00
|
|
|
}
|