mirror of https://github.com/YTVanced/VancedMicroG
Avoid notification coming back
This commit is contained in:
parent
478c46f4bb
commit
0a4fd6158a
|
@ -8,41 +8,39 @@ import android.content.Intent;
|
|||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import com.mgoogle.android.gms.R;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class StatusNotification {
|
||||
|
||||
private static int notificationID;
|
||||
private static boolean notificationExists = false;
|
||||
|
||||
public static boolean Notify(Context context) {
|
||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (!powerManager.isIgnoringBatteryOptimizations(context.getPackageName())) {
|
||||
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
StatusBarNotification[] notifications = manager.getActiveNotifications();
|
||||
for (StatusBarNotification notification : notifications) {
|
||||
if (notification.getId() == notificationID) {
|
||||
return false;
|
||||
}
|
||||
if (notificationExists) {
|
||||
return false;
|
||||
}
|
||||
|
||||
buildStatusNotification(context);
|
||||
} else {
|
||||
if (notificationExists) {
|
||||
((NotificationManager)
|
||||
context.getSystemService(Context.NOTIFICATION_SERVICE)).cancel(notificationID);
|
||||
notificationExists = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void buildStatusNotification(Context context) {
|
||||
notificationID = createNotificationID();
|
||||
notificationID = 1;
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
|
||||
|
@ -52,29 +50,27 @@ public class StatusNotification {
|
|||
String notificationChannelID = "foreground-service";
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(notificationChannelID, context.getResources().getString(R.string.notification_service_name), NotificationManager.IMPORTANCE_LOW);
|
||||
NotificationChannel channel = new NotificationChannel(notificationChannelID,
|
||||
context.getResources().getString(R.string.notification_service_name),
|
||||
NotificationManager.IMPORTANCE_LOW);
|
||||
channel.setShowBadge(true);
|
||||
channel.setLockscreenVisibility(0);
|
||||
channel.setVibrationPattern(new long[0]);
|
||||
context.getSystemService(NotificationManager.class).createNotificationChannel(channel);
|
||||
}
|
||||
NotificationCompat.Builder notification = new NotificationCompat.Builder(context, notificationChannelID)
|
||||
.setAutoCancel(true)
|
||||
.setOngoing(true)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setContentTitle(context.getResources().getString(R.string.notification_service_title))
|
||||
.setContentText(context.getResources().getString(R.string.notification_service_content))
|
||||
.setSmallIcon(R.drawable.ic_foreground_notification);
|
||||
.setSmallIcon(R.drawable.ic_foreground_notification)
|
||||
.setSubText(context.getResources().getString(R.string.notification_service_title))
|
||||
.setContentTitle(context.getResources().getString(R.string.notification_service_content))
|
||||
.setContentText(context.getResources().getString(R.string.notification_service_subcontent));
|
||||
|
||||
NotificationManager manager =
|
||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
manager.notify(notificationID, notification.build());
|
||||
}
|
||||
|
||||
private static int createNotificationID() {
|
||||
Date currentDate = new Date();
|
||||
int id = Integer.parseInt(new SimpleDateFormat("ddHHmmss", Locale.US).format(currentDate));
|
||||
|
||||
return id;
|
||||
notificationExists = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,10 @@
|
|||
<string name="gms_settings_name">Impostazioni di Vanced microG</string>
|
||||
<string name="gms_settings_summary">Configurazione di Vanced microG.</string>
|
||||
|
||||
<string name="notification_service_name">Primo Piano</string>
|
||||
<string name="notification_service_title">Esecuzione in background</string>
|
||||
<string name="notification_service_content">Tocca qui per escludere microg dal risparmio energetico</string>
|
||||
<string name="notification_service_name">Esclusione Risparmio Energetico</string>
|
||||
<string name="notification_service_title">Escludi i microg dal risparmio energetico</string>
|
||||
<string name="notification_service_content">Per rimuovere questa notifica chiudi l\'app Vanced</string>
|
||||
<string name="notification_service_subcontent">dalla lista delle app in secondo piano e riaprila</string>
|
||||
|
||||
<string name="just_a_sec">Solo un secondo…</string>
|
||||
<string name="ask_permission_tos">Continuando, consentirai a quest\'app e a Google di utilizzare le tue informazioni in conformità con i rispettivi termini di servizio e politiche sulla riservatezza.</string>
|
||||
|
|
|
@ -18,9 +18,10 @@
|
|||
<string name="gms_settings_name">Vanced microG Settings</string>
|
||||
<string name="gms_settings_summary">Setup Vanced microG.</string>
|
||||
|
||||
<string name="notification_service_name">Foreground Service</string>
|
||||
<string name="notification_service_title">Running in background</string>
|
||||
<string name="notification_service_content">Tap me to disable battery saving for microG</string>
|
||||
<string name="notification_service_name">Battery Saving Exclusion</string>
|
||||
<string name="notification_service_title">Exclude microG from battery saving</string>
|
||||
<string name="notification_service_content">To remove this notification close Vanced</string>
|
||||
<string name="notification_service_subcontent">app from task manager and reopen it</string>
|
||||
|
||||
<string name="just_a_sec">Just a sec…</string>
|
||||
<string name="ask_permission_tos">By continuing, you allow this app and Google to use your information in accordance with their respective terms of service and privacy policies.</string>
|
||||
|
|
Loading…
Reference in New Issue