Skip to content

Commit

Permalink
Fixes for Pending Intent in Service (#27)
Browse files Browse the repository at this point in the history
Give intents readable actions, add flags for sdk 31+

Co-authored-by: KurvigerPatrick <[email protected]>
  • Loading branch information
avalanchas and KurvigerPatrick authored Nov 21, 2022
1 parent 41218bd commit 998eac9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

Maplibre welcomes participation and contributions from everyone.

### v1.2.0 - unreleased
### v1.2.0 - November 21, 2022

- Fixed unit tests and updated some build dependencies.
- Added Flags for pending intents which are required in Android 31+
- Added an action name to pending intent to identify it externally

### v1.1.1 and prior version - October 21, 2022

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
*/
class MapboxNavigationNotification implements NavigationNotification {

private static final String END_NAVIGATION_ACTION = "com.mapbox.intent.action.END_NAVIGATION";
private static final int INTENT_FLAGS = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ?
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE :
PendingIntent.FLAG_UPDATE_CURRENT;

private NotificationCompat.Builder notificationBuilder;
private NotificationManager notificationManager;
private Notification notification;
Expand Down Expand Up @@ -142,7 +145,8 @@ private PendingIntent createPendingOpenIntent(Context context) {
PackageManager pm = context.getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(context.getPackageName());
intent.setPackage(null);
return PendingIntent.getActivity(context, 0, intent, 0);
intent.setAction(OPEN_NAVIGATION_ACTION);
return PendingIntent.getActivity(context, 0, intent, INTENT_FLAGS);
}

private void registerReceiver(Context context) {
Expand Down Expand Up @@ -235,7 +239,7 @@ private boolean newManeuverId(LegStep step) {

private PendingIntent createPendingCloseIntent(Context context) {
Intent endNavigationBtn = new Intent(END_NAVIGATION_ACTION);
return PendingIntent.getBroadcast(context, 0, endNavigationBtn, 0);
return PendingIntent.getBroadcast(context, 0, endNavigationBtn, INTENT_FLAGS);
}

private void onEndNavigationBtnClick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
public interface NavigationNotification {

String END_NAVIGATION_ACTION = "com.mapbox.intent.action.END_NAVIGATION";
String OPEN_NAVIGATION_ACTION = "com.mapbox.intent.action.OPEN_NAVIGATION";

/**
* Provides a custom {@link Notification} to launch
* with the {@link com.mapbox.services.android.navigation.v5.navigation.NavigationService}, specifically
Expand Down

0 comments on commit 998eac9

Please sign in to comment.