Open notifications screen when clicking on persistent notification
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Amab 2022-12-18 14:29:57 +01:00
parent 9cf77930a9
commit f414ef0924
2 changed files with 19 additions and 3 deletions

View File

@ -26,6 +26,7 @@ import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Build;
@ -33,6 +34,7 @@ import android.os.Build;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import es.ugr.swad.swadroid.modules.notifications.Notifications;
import es.ugr.swad.swadroid.utils.NotificationUtils;
/**
@ -136,14 +138,15 @@ public class AlertNotificationFactory {
return notifBuilder.build();
}
public static Notification createBackgroundNotification(Context context, String contentTitle, int smallIcon, int largeIcon) {
public static Notification createBackgroundNotification(Context context, String contentTitle, int smallIcon, int largeIcon, PendingIntent pendingIntent) {
NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context, SWADROID_CHANNEL_ID)
.setOngoing(true)
.setSmallIcon(smallIcon)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), largeIcon))
.setContentTitle(contentTitle)
.setPriority(NotificationManager.IMPORTANCE_HIGH)
.setCategory(Notification.CATEGORY_SERVICE);
.setCategory(Notification.CATEGORY_SERVICE)
.setContentIntent(pendingIntent);
//Create alert
return notifBuilder.build();

View File

@ -217,11 +217,24 @@ public class NotificationsSyncAdapterService extends Service {
}
private void startCustomForeground() {
Intent notificationIntent = new Intent(this, Notifications.class);
PendingIntent pendingIntent;
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//single top to avoid creating many activity stacks queue
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(this,
0,
notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
Notification notification = AlertNotificationFactory.createBackgroundNotification(
this,
getString(R.string.appRunningBackground),
R.drawable.ic_launcher_swadroid_notif,
R.drawable.ic_launcher_swadroid);
R.drawable.ic_launcher_swadroid,
pendingIntent);
startForeground(2, notification);
}