Commit 939d29fa authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Added method for creating notification channels

parent bb703f18
package com.frostnerd.dnsserver.util;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import com.frostnerd.dnsserver.R;
import com.frostnerd.dnsserver.database.DatabaseHelper;
import com.frostnerd.dnsserver.database.ServerDatabaseHelper;
import com.frostnerd.dnsserver.database.entities.main.DNSServerSetting;
import com.frostnerd.dnsserver.database.entities.main.IPPortPair;
import com.frostnerd.utils.networking.NetworkUtil;
import java.util.HashMap;
import java.util.regex.Pattern;
/**
......@@ -86,4 +86,27 @@ public final class Util {
}
}
}
public static String createNotificationChannel(Context context, boolean allowIconHiding){
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
if(allowIconHiding){
NotificationChannel channel = new NotificationChannel("noIconChannel", context.getString(R.string.notification_channel_hiddenicon), NotificationManager.IMPORTANCE_MIN);
channel.enableLights(false);
channel.enableVibration(false);
channel.setDescription(context.getString(R.string.notification_channel_hiddenicon_description));
notificationManager.createNotificationChannel(channel);
return "noIconChannel";
}else{
NotificationChannel channel = new NotificationChannel("defaultchannel", context.getString(R.string.notification_channel_default), NotificationManager.IMPORTANCE_LOW);
channel.enableLights(false);
channel.enableVibration(false);
channel.setDescription(context.getString(R.string.notification_channel_default_description));
notificationManager.createNotificationChannel(channel);
return "defaultchannel";
}
}else{
return "defaultchannel";
}
}
}
......@@ -3,4 +3,9 @@
<string name="app_name">DNS Server</string>
<string name="new_server">Neuer Server</string>
<string name="server_port_label">Port: [x]</string>
<string name="notification_channel_default">Standardchannel</string>
<string name="notification_channel_default_description">Standardchannel für Benachrichtigungen</string>
<string name="notification_channel_hiddenicon">Channel ohne Icon</string>
<string name="notification_channel_hiddenicon_description">Dieser Channel zeigt kein Symbol in der Benachrichtigungsleiste</string>
<string name="x_servers_running">[x] servers aktiv</string>
</resources>
\ No newline at end of file
......@@ -2,4 +2,9 @@
<string name="app_name">DNS Server</string>
<string name="new_server">New server</string>
<string name="server_port_label">Port: [x]</string>
<string name="notification_channel_hiddenicon">Channel with no icon</string>
<string name="notification_channel_hiddenicon_description">This channel shows no icon in the notification bar</string>
<string name="notification_channel_default">Default Channel</string>
<string name="notification_channel_default_description">Default channel for posting notifications.</string>
<string name="x_servers_running">[x] servers running</string>
</resources>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment