diff options
author | ByteHamster <info@bytehamster.com> | 2020-05-27 11:02:41 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-05-27 11:02:41 +0200 |
commit | 018a91d66ce42e31e493117467dfa8be76301f26 (patch) | |
tree | 16f609cc6404f110b265cb1200d839a0c0ba5938 /core/src | |
parent | 4b2aa3e8b0139932531ffbe35b4983d01008eaf5 (diff) | |
download | AntennaPod-018a91d66ce42e31e493117467dfa8be76301f26.zip |
Made PendingIntent request codes unique
Diffstat (limited to 'core/src')
5 files changed, 31 insertions, 21 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java b/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java index 4562f1393..f39ac0df8 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java @@ -103,12 +103,8 @@ public class PlayerWidgetJobService extends SafeJobIntentService { AppWidgetManager manager = AppWidgetManager.getInstance(this); int[] widgetIds = manager.getAppWidgetIds(playerWidget); RemoteViews views = new RemoteViews(getPackageName(), R.layout.player_widget); - PendingIntent startMediaplayer = PendingIntent.getActivity(this, 0, - PlaybackService.getPlayerActivityIntent(this), 0); - - final PendingIntent startAppPending = PendingIntent.getActivity(this, 0, - PlaybackService.getPlayerActivityIntent(this), - PendingIntent.FLAG_UPDATE_CURRENT); + final PendingIntent startMediaPlayer = PendingIntent.getActivity(this, R.id.pending_intent_player_activity, + PlaybackService.getPlayerActivityIntent(this), PendingIntent.FLAG_UPDATE_CURRENT); boolean nothingPlaying = false; Playable media; @@ -122,7 +118,7 @@ public class PlayerWidgetJobService extends SafeJobIntentService { } if (media != null) { - views.setOnClickPendingIntent(R.id.layout_left, startMediaplayer); + views.setOnClickPendingIntent(R.id.layout_left, startMediaPlayer); try { Bitmap icon = null; @@ -170,8 +166,8 @@ public class PlayerWidgetJobService extends SafeJobIntentService { if (nothingPlaying) { // start the app if they click anything - views.setOnClickPendingIntent(R.id.layout_left, startAppPending); - views.setOnClickPendingIntent(R.id.butPlay, startAppPending); + views.setOnClickPendingIntent(R.id.layout_left, startMediaPlayer); + views.setOnClickPendingIntent(R.id.butPlay, startMediaPlayer); views.setViewVisibility(R.id.txtvProgress, View.GONE); views.setViewVisibility(R.id.txtvTitle, View.GONE); views.setViewVisibility(R.id.txtNoPlaying, View.VISIBLE); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 33a2a72ff..f25b0a5a8 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -542,9 +542,11 @@ public class PlaybackService extends MediaBrowserServiceCompat { intentAllowThisTime.putExtra(EXTRA_ALLOW_STREAM_THIS_TIME, true); PendingIntent pendingIntentAllowThisTime; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - pendingIntentAllowThisTime = PendingIntent.getForegroundService(this, 0, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT); + pendingIntentAllowThisTime = PendingIntent.getForegroundService(this, + R.id.pending_intent_allow_stream_this_time, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT); } else { - pendingIntentAllowThisTime = PendingIntent.getService(this, 0, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT); + pendingIntentAllowThisTime = PendingIntent.getService(this, + R.id.pending_intent_allow_stream_this_time, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT); } Intent intentAlwaysAllow = new Intent(intentAllowThisTime); @@ -552,12 +554,15 @@ public class PlaybackService extends MediaBrowserServiceCompat { intentAlwaysAllow.putExtra(EXTRA_ALLOW_STREAM_ALWAYS, true); PendingIntent pendingIntentAlwaysAllow; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - pendingIntentAlwaysAllow = PendingIntent.getForegroundService(this, 0, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT); + pendingIntentAlwaysAllow = PendingIntent.getForegroundService(this, + R.id.pending_intent_allow_stream_always, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT); } else { - pendingIntentAlwaysAllow = PendingIntent.getService(this, 0, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT); + pendingIntentAlwaysAllow = PendingIntent.getService(this, + R.id.pending_intent_allow_stream_always, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT); } - NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_USER_ACTION) + NotificationCompat.Builder builder = new NotificationCompat.Builder(this, + NotificationUtils.CHANNEL_ID_USER_ACTION) .setSmallIcon(R.drawable.ic_stream_white) .setContentTitle(getString(R.string.confirm_mobile_streaming_notification_title)) .setContentText(getString(R.string.confirm_mobile_streaming_notification_message)) @@ -1238,9 +1243,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { } } if (!Thread.currentThread().isInterrupted() && stateManager.hasReceivedValidStartCommand()) { - mediaSession.setSessionActivity(PendingIntent.getActivity(this, 0, - PlaybackService.getPlayerActivityIntent(this), - PendingIntent.FLAG_UPDATE_CURRENT)); + mediaSession.setSessionActivity(PendingIntent.getActivity(this, R.id.pending_intent_player_activity, + PlaybackService.getPlayerActivityIntent(this), PendingIntent.FLAG_UPDATE_CURRENT)); try { mediaSession.setMetadata(builder.build()); } catch (OutOfMemoryError e) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java index 174b43846..915e77f6c 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java @@ -146,8 +146,8 @@ public class PlaybackServiceNotificationBuilder { } private PendingIntent getPlayerActivityPendingIntent() { - return PendingIntent.getActivity(context, 0, PlaybackService.getPlayerActivityIntent(context), - PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getActivity(context, R.id.pending_intent_player_activity, + PlaybackService.getPlayerActivityIntent(context), PendingIntent.FLAG_UPDATE_CURRENT); } private void addActions(NotificationCompat.Builder notification, MediaSessionCompat.Token mediaSessionToken, diff --git a/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java b/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java index 6985e4421..4c89ebc19 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java @@ -488,8 +488,8 @@ public class SyncService extends Worker { Intent intent = getApplicationContext().getPackageManager().getLaunchIntentForPackage( getApplicationContext().getPackageName()); - PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), + R.id.pending_intent_sync_error, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new NotificationCompat.Builder(getApplicationContext(), NotificationUtils.CHANNEL_ID_ERROR) .setContentTitle(getApplicationContext().getString(R.string.gpodnetsync_error_title)) diff --git a/core/src/main/res/values/ids.xml b/core/src/main/res/values/ids.xml index 1d1777ef1..8443759b4 100644 --- a/core/src/main/res/values/ids.xml +++ b/core/src/main/res/values/ids.xml @@ -25,4 +25,14 @@ <item name="undobar_button" type="id"/> <item name="undobar_message" type="id"/> <item name="episode_item_view_holder" type="id"/> + + <!-- PendingIntent objects that use the same action but different extras need to use a unique request code --> + <item name="pending_intent_download_service_notification" type="id"/> + <item name="pending_intent_download_service_auth" type="id"/> + <item name="pending_intent_download_service_report" type="id"/> + <item name="pending_intent_download_service_autodownload_report" type="id"/> + <item name="pending_intent_allow_stream_always" type="id"/> + <item name="pending_intent_allow_stream_this_time" type="id"/> + <item name="pending_intent_player_activity" type="id"/> + <item name="pending_intent_sync_error" type="id"/> </resources>
\ No newline at end of file |