Test notifications for API 21 and above

This commit is contained in:
Oizaro 2020-09-07 04:53:54 +02:00
parent f4b73f3fdb
commit aee60e4d91
3 changed files with 5 additions and 21 deletions

View File

@ -2,8 +2,6 @@ package org.microg.gms.common;
import android.app.ActivityManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ComponentName;
@ -61,24 +59,18 @@ public class ForegroundServiceContext extends ContextWrapper {
}
public static void completeForegroundService(Service service, Intent intent, String tag) {
if (intent.getBooleanExtra(EXTRA_FOREGROUND, false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (intent.getBooleanExtra(EXTRA_FOREGROUND, false)) {
Log.d(tag, "Started in foreground mode.");
service.startForeground(tag.hashCode(), buildForegroundNotification(service));
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
private static Notification buildForegroundNotification(Context context) {
NotificationChannel channel = new NotificationChannel("foreground-service", context.getResources().getString(R.string.notification_service_name), NotificationManager.IMPORTANCE_MIN);
channel.setShowBadge(false);
channel.setLockscreenVisibility(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);
return new Notification.Builder(context, channel.getId())
return new Notification.Builder(context)
.setOngoing(true)
.setContentIntent(pendingIntent)
.setContentTitle(context.getResources().getString(R.string.notification_service_title))

View File

@ -18,8 +18,6 @@ package org.microg.gms.gcm;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ComponentName;
@ -40,7 +38,6 @@ import android.os.SystemClock;
import android.os.UserHandle;
import android.util.Log;
import androidx.annotation.RequiresApi;
import androidx.legacy.content.WakefulBroadcastReceiver;
import com.mgoogle.android.gms.R;
@ -318,14 +315,9 @@ public class McsService extends Service implements Handler.Callback {
return START_REDELIVER_INTENT;
}
@RequiresApi(api = Build.VERSION_CODES.O)
private Notification buildForegroundNotification() {
NotificationChannel channel = new NotificationChannel("foreground-service", getString(R.string.notification_service_name), NotificationManager.IMPORTANCE_LOW);
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
channel.setShowBadge(false);
getSystemService(NotificationManager.class).createNotificationChannel(channel);
return new Notification.Builder(this, channel.getId())
.setOngoing(true)
return new Notification.Builder(this)
.setCategory(Notification.CATEGORY_MESSAGE)
.setContentTitle(this.getResources().getString(R.string.notification_service_title))
.setSmallIcon(android.R.drawable.stat_notify_sync)
.build();

View File

@ -82,7 +82,7 @@ Questo potrà richiedere un paio di minuti"</string>
<string name="checkin_last_registration">Ultima registrazione: <xliff:g example="Yesterday, 02:20 PM">%1$s</xliff:g></string>
<string name="cond_gcm_bat_title">Ottimizzazione batteria attivata</string>
<string name="cond_gcm_bat_summary">Hai attivato l'\opzione Messaggistica Cloud Google ma i Servizi Vanced microG risultano al momento limitati dall\'ottimizzazione energetica di sistema. Se desideri ricevere le notifiche push, escludi i microG da questa ottimizzazione.</string>
<string name="cond_gcm_bat_summary">Hai attivato l\'opzione Messaggistica Cloud Google ma i Servizi Vanced microG risultano al momento limitati dall\'ottimizzazione energetica di sistema. Se desideri ricevere le notifiche push, escludi i microG da questa ottimizzazione.</string>
<string name="cond_gcm_bat_action">Ignore ottimizzazione</string>
<string name="prefs_account">Preferenze account</string>