diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-05-08 17:23:24 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-05-08 17:23:24 +0000 |
commit | 16d926fdf8ce5f3e0354ad78fc0e97f57fab82c8 (patch) | |
tree | 41baa6bbe0314f851ab054a150fe6aa97c5c4468 /app | |
parent | d85ce883f41f826861eb867224b37d711ca5da2a (diff) | |
download | infinity-for-reddit-16d926fdf8ce5f3e0354ad78fc0e97f57fab82c8.tar infinity-for-reddit-16d926fdf8ce5f3e0354ad78fc0e97f57fab82c8.tar.gz infinity-for-reddit-16d926fdf8ce5f3e0354ad78fc0e97f57fab82c8.tar.bz2 infinity-for-reddit-16d926fdf8ce5f3e0354ad78fc0e97f57fab82c8.tar.lz infinity-for-reddit-16d926fdf8ce5f3e0354ad78fc0e97f57fab82c8.tar.xz infinity-for-reddit-16d926fdf8ce5f3e0354ad78fc0e97f57fab82c8.tar.zst infinity-for-reddit-16d926fdf8ce5f3e0354ad78fc0e97f57fab82c8.zip |
Save pending intent flags in a variable to not show error in DownloadMediaService and DownloadRedditVideoService.
Diffstat (limited to '')
2 files changed, 10 insertions, 6 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java index 0013f99e..872ff654 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java @@ -436,11 +436,13 @@ public class DownloadMediaService extends Service { builder.setContentText(getString(contentStringResId)); } if (mediaUri != null) { + int pendingIntentFlags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_CANCEL_CURRENT; + Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(mediaUri, mimeType); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - PendingIntent pendingIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.getActivity(DownloadMediaService.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE) : PendingIntent.getActivity(DownloadMediaService.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent pendingIntent = PendingIntent.getActivity(DownloadMediaService.this, 0, intent, pendingIntentFlags); builder.setContentIntent(pendingIntent); Intent shareIntent = new Intent(); @@ -449,14 +451,14 @@ public class DownloadMediaService extends Service { shareIntent.setType(mimeType); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Intent intentAction = Intent.createChooser(shareIntent, getString(R.string.share)); - PendingIntent shareActionPendingIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.getActivity(this, 1, intentAction, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE) : PendingIntent.getActivity(this, 1, intentAction, PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent shareActionPendingIntent = PendingIntent.getActivity(this, 1, intentAction, pendingIntentFlags); builder.addAction(new NotificationCompat.Action(R.drawable.ic_notification, getString(R.string.share), shareActionPendingIntent)); Intent deleteIntent = new Intent(this, DownloadedMediaDeleteActionBroadcastReceiver.class); deleteIntent.setData(mediaUri); deleteIntent.putExtra(DownloadedMediaDeleteActionBroadcastReceiver.EXTRA_NOTIFICATION_ID, getNotificationId(mediaType, randomNotificationIdOffset)); - PendingIntent deleteActionPendingIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.getBroadcast(this, 2, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE) : PendingIntent.getBroadcast(this, 2, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent deleteActionPendingIntent = PendingIntent.getBroadcast(this, 2, deleteIntent, pendingIntentFlags); builder.addAction(new NotificationCompat.Action(R.drawable.ic_notification, getString(R.string.delete), deleteActionPendingIntent)); } notificationManager.notify(getNotificationId(mediaType, randomNotificationIdOffset), builder.build()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java index 3328e833..f9647da4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java @@ -640,11 +640,13 @@ public class DownloadRedditVideoService extends Service { builder.setContentText(getString(contentStringResId)); } if (mediaUri != null) { + int pendingIntentFlags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_CANCEL_CURRENT; + Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(mediaUri, "video/mp4"); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - PendingIntent pendingIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE) : PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, pendingIntentFlags); builder.setContentIntent(pendingIntent); @@ -654,13 +656,13 @@ public class DownloadRedditVideoService extends Service { shareIntent.setType("video/mp4"); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Intent intentAction = Intent.createChooser(shareIntent, getString(R.string.share)); - PendingIntent shareActionPendingIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.getActivity(this, 1, intentAction, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE) : PendingIntent.getActivity(this, 1, intentAction, PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent shareActionPendingIntent = PendingIntent.getActivity(this, 1, intentAction, pendingIntentFlags); builder.addAction(new NotificationCompat.Action(R.drawable.ic_notification, getString(R.string.share), shareActionPendingIntent)); Intent deleteIntent = new Intent(this, DownloadedMediaDeleteActionBroadcastReceiver.class); deleteIntent.setData(mediaUri); deleteIntent.putExtra(DownloadedMediaDeleteActionBroadcastReceiver.EXTRA_NOTIFICATION_ID, NotificationUtils.DOWNLOAD_REDDIT_VIDEO_NOTIFICATION_ID + randomNotificationIdOffset); - PendingIntent deleteActionPendingIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.getBroadcast(this, 2, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE) : PendingIntent.getBroadcast(this, 2, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent deleteActionPendingIntent = PendingIntent.getBroadcast(this, 2, deleteIntent, pendingIntentFlags); builder.addAction(new NotificationCompat.Action(R.drawable.ic_notification, getString(R.string.delete), deleteActionPendingIntent)); } else { builder.setContentIntent(null); |