Skip to content

Commit ea12d60

Browse files
committed
Update to target SDK 33 (android 13)
add notification channel for SDK >=26
1 parent b0e2a5f commit ea12d60

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

client/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
22

33
android
44
{
5-
compileSdkVersion 27
5+
compileSdkVersion 33
66
defaultConfig
77
{
88
applicationId "net.kzxiv.notify.client"

client/src/main/java/net/kzxiv/notify/client/ConfigurationActivity.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ protected void onCreate(Bundle savedInstanceState)
1919

2020
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)
2121
{
22+
int NOTIFICATION_ID = 0;
23+
String CHANNEL_ID = "notifikator";
24+
2225
Resources res = getResources();
2326
if (res.getString(R.string.key_send).equals(preference.getKey()))
2427
{
@@ -33,7 +36,22 @@ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preferen
3336
Bitmap largeIconBitmap = largeIconDrawable.getBitmap();
3437
nb.setLargeIcon(largeIconBitmap);
3538

36-
mgr.notify(0, nb.build());
39+
// `VERSION_CODES.O` means SDK 26
40+
// Thanks Google, very readable
41+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
42+
// notification channel setup
43+
NotificationChannel mChannel = null;
44+
mChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_ID, NotificationManager.IMPORTANCE_LOW);
45+
mChannel.setDescription("");
46+
mChannel.enableLights(true);
47+
mChannel.setLightColor(Color.GREEN);
48+
mChannel.enableVibration(false);
49+
mgr.createNotificationChannel(mChannel);
50+
51+
nb.setChannelId(CHANNEL_ID);
52+
}
53+
54+
mgr.notify(NOTIFICATION_ID, nb.build());
3755
return false;
3856
}
3957

0 commit comments

Comments
 (0)