-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOreoAndAboveNotification.java
More file actions
60 lines (49 loc) · 2.19 KB
/
Copy pathOreoAndAboveNotification.java
File metadata and controls
60 lines (49 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.codewithharry.firebase.notifications;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.ContextWrapper;
import android.net.Uri;
import android.os.Build;
import androidx.annotation.RequiresApi;
public class OreoAndAboveNotification extends ContextWrapper {
private static final String ID = "some_id";
private static final String NAME = "FirebaseAPP";
private NotificationManager notificationManager;
public OreoAndAboveNotification(Context base) {
super(base);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
createChannel();
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
private void createChannel() {
NotificationChannel notificationChannel = new NotificationChannel(ID, NAME, NotificationManager.IMPORTANCE_DEFAULT);
notificationChannel.enableLights(true);
notificationChannel.enableVibration(true);
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
getManager().createNotificationChannel(notificationChannel);
}
public NotificationManager getManager() {
if (notificationManager == null) {
notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
}
return notificationManager;
}
@RequiresApi(api = Build.VERSION_CODES.O)
public Notification.Builder getONotification(String title,
String body,
PendingIntent pIntent,
Uri soundUri,
String icon) {
return new Notification.Builder(getApplicationContext(), ID)
.setContentIntent(pIntent)
.setContentTitle(title)
.setContentText(body)
.setSound(soundUri)
.setAutoCancel(true)
.setSmallIcon(Integer.parseInt(icon));
}
}