Skip to content
Snippets Groups Projects
Commit 1f0c385a authored by akwizgran's avatar akwizgran
Browse files

Merge branch '1124-notification-channel-crash' into 'master'

Use NotificationChannel for foreground service to avoid crash on Android 8.1

Closes #1124

See merge request !634
parents a50e13c2 986ea05f
No related branches found
No related tags found
No related merge requests found
package org.briarproject.briar.android; package org.briarproject.briar.android;
import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
...@@ -73,8 +74,20 @@ public class BriarService extends Service { ...@@ -73,8 +74,20 @@ public class BriarService extends Service {
stopSelf(); stopSelf();
return; return;
} }
// Create mandatory notification channel
String channelId = "foregroundService";
if (Build.VERSION.SDK_INT >= 26) {
NotificationChannel channel = new NotificationChannel(channelId,
getString(R.string.app_name),
NotificationManager.IMPORTANCE_NONE);
channel.setLockscreenVisibility(VISIBILITY_SECRET);
NotificationManager nm =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.createNotificationChannel(channel);
}
// Show an ongoing notification that the service is running // Show an ongoing notification that the service is running
NotificationCompat.Builder b = new NotificationCompat.Builder(this); NotificationCompat.Builder b =
new NotificationCompat.Builder(this, channelId);
b.setSmallIcon(R.drawable.notification_ongoing); b.setSmallIcon(R.drawable.notification_ongoing);
b.setColor(ContextCompat.getColor(this, R.color.briar_primary)); b.setColor(ContextCompat.getColor(this, R.color.briar_primary));
b.setContentTitle(getText(R.string.ongoing_notification_title)); b.setContentTitle(getText(R.string.ongoing_notification_title));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment