Improve notification

This commit is contained in:
KevinX8 2020-07-29 15:32:19 +03:00
parent 4d001f0089
commit d5a5df2f0f

View File

@ -4,6 +4,7 @@ import android.app.ActivityManager;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
@ -11,6 +12,7 @@ import android.content.ContextWrapper;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.PowerManager; import android.os.PowerManager;
import android.provider.Settings;
import android.util.Log; import android.util.Log;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
@ -71,11 +73,16 @@ public class ForegroundServiceContext extends ContextWrapper {
channel.setShowBadge(false); channel.setShowBadge(false);
channel.setLockscreenVisibility(0); channel.setLockscreenVisibility(0);
channel.setVibrationPattern(new long[0]); channel.setVibrationPattern(new long[0]);
Intent mIntent = new Intent();
mIntent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, mIntent, 0);
context.getSystemService(NotificationManager.class).createNotificationChannel(channel); context.getSystemService(NotificationManager.class).createNotificationChannel(channel);
return new Notification.Builder(context, channel.getId()) return new Notification.Builder(context, channel.getId())
.setOngoing(true) .setOngoing(true)
.setContentIntent(pendingIntent)
.setContentTitle("Running in background") .setContentTitle("Running in background")
.setContentText("Disable battery optimisations for microG to remove me") .setContentText("Tap me to disable battery optimisations for microG")
.setSmallIcon(R.drawable.ic_foreground_notification) .setSmallIcon(R.drawable.ic_foreground_notification)
.build(); .build();
} }