Fix notification compatibility for API 26 and higher

This commit is contained in:
Oizaro 2020-09-07 19:01:10 +02:00
parent e0dc7f5b40
commit 21c2f51ea6

View File

@ -75,7 +75,16 @@ public class ForegroundServiceContext extends ContextWrapper {
mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, mIntent, 0); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, mIntent, 0);
return new NotificationCompat.Builder(context, "foreground-service") String notificationChannelID = "foreground-service";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(notificationChannelID, context.getResources().getString(R.string.notification_service_name), NotificationManager.IMPORTANCE_MIN);
channel.setShowBadge(false);
channel.setLockscreenVisibility(0);
channel.setVibrationPattern(new long[0]);
context.getSystemService(NotificationManager.class).createNotificationChannel(channel);
}
return new NotificationCompat.Builder(context, notificationChannelID)
.setOngoing(true) .setOngoing(true)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setContentTitle(context.getResources().getString(R.string.notification_service_title)) .setContentTitle(context.getResources().getString(R.string.notification_service_title))