Skip to content
Snippets Groups Projects
Commit 74e3fee7 authored by akwizgran's avatar akwizgran
Browse files

Merge branch '1124-notification-channel-crash-beta' into 'maintenance-0.16'

Beta: Use NotificationChannel for foreground service to avoid crash on Android 8.1

See merge request !635
parents 48918f47 05aac696
No related branches found
No related tags found
No related merge requests found
package org.briarproject.briar.android;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
......@@ -73,8 +74,20 @@ public class BriarService extends Service {
stopSelf();
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
NotificationCompat.Builder b = new NotificationCompat.Builder(this);
NotificationCompat.Builder b =
new NotificationCompat.Builder(this, channelId);
b.setSmallIcon(R.drawable.notification_ongoing);
b.setColor(ContextCompat.getColor(this, R.color.briar_primary));
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