diff --git a/onebusaway-android/build.gradle b/onebusaway-android/build.gradle index 1c06c7297..d748aeedd 100644 --- a/onebusaway-android/build.gradle +++ b/onebusaway-android/build.gradle @@ -35,11 +35,11 @@ repositories { } android { - compileSdk 33 + compileSdk 34 defaultConfig { minSdkVersion 21 - targetSdkVersion 33 + targetSdkVersion 34 versionCode 143 versionName "2.14.0" diff --git a/onebusaway-android/src/main/AndroidManifest.xml b/onebusaway-android/src/main/AndroidManifest.xml index 03db61dca..e8b165d1c 100644 --- a/onebusaway-android/src/main/AndroidManifest.xml +++ b/onebusaway-android/src/main/AndroidManifest.xml @@ -27,6 +27,7 @@ + @@ -37,6 +38,7 @@ + @@ -294,6 +296,7 @@ diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/nav/NavigationService.java b/onebusaway-android/src/main/java/org/onebusaway/android/nav/NavigationService.java index 3600230f8..b3ca057f8 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/nav/NavigationService.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/nav/NavigationService.java @@ -23,6 +23,7 @@ import android.app.Service; import android.content.Context; import android.content.Intent; +import android.content.pm.ServiceInfo; import android.location.Location; import android.os.Build; import android.os.IBinder; @@ -155,7 +156,11 @@ public int onStartCommand(Intent intent, int flags, int startId) { mNavProvider.navigate(path); } Notification notification = mNavProvider.getForegroundStartingNotification(); - startForeground(NavigationServiceProvider.NOTIFICATION_ID, notification); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + startForeground(NavigationServiceProvider.NOTIFICATION_ID, notification,ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION); + }else{ + startForeground(NavigationServiceProvider.NOTIFICATION_ID, notification); + } return START_STICKY; } diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/TripService.java b/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/TripService.java index 3e00b27a8..fdc1f08ff 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/TripService.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/TripService.java @@ -23,6 +23,7 @@ import android.app.Service; import android.content.Context; import android.content.Intent; +import android.content.pm.ServiceInfo; import android.net.Uri; import android.os.Binder; import android.os.Build; @@ -170,7 +171,12 @@ public int onStartCommand(Intent intent, int flags, int startId) { .setContentText(foregroundNotifyText) .setContentIntent(pendingIntent).build(); - startForeground(FOREGROUND_NOTIFICATION_ID, notification); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + startForeground(FOREGROUND_NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE); + }else{ + startForeground(FOREGROUND_NOTIFICATION_ID, notification); + } } return handleCommand(intent, startId); } diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/ui/TripDetailsListFragment.java b/onebusaway-android/src/main/java/org/onebusaway/android/ui/TripDetailsListFragment.java index 07a19d548..5be19cfeb 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/ui/TripDetailsListFragment.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/ui/TripDetailsListFragment.java @@ -16,6 +16,7 @@ */ package org.onebusaway.android.ui; +import android.Manifest; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; @@ -53,6 +54,7 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.core.app.ActivityCompat; import androidx.core.graphics.drawable.DrawableCompat; import androidx.loader.app.LoaderManager; import androidx.loader.content.AsyncTaskLoader; @@ -96,6 +98,8 @@ import java.util.GregorianCalendar; import java.util.concurrent.TimeUnit; +import static org.onebusaway.android.util.PermissionUtils.NOTIFICATION_PERMISSION_REQUEST; + public class TripDetailsListFragment extends ListFragment { public static final String TAG = "TripDetailsListFragment"; @@ -554,6 +558,12 @@ public void onClick(DialogInterface dialog, int which) { ObaAnalytics.reportUiEvent(mFirebaseAnalytics, getString(R.string.analytics_label_destination_reminder), getString(R.string.analytics_label_destination_reminder_variant_started)); + // Request the user to grant the POST_NOTIFICATIONS permission. + ActivityCompat.requestPermissions(getActivity(), + new String[] {Manifest.permission.POST_NOTIFICATIONS}, + NOTIFICATION_PERMISSION_REQUEST); + dialog.dismiss(); + startNavigationService(setUpNavigationService(position)); Toast.makeText(Application.get(), Application.get().getString(R.string.destination_reminder_title), @@ -1192,7 +1202,11 @@ private void registerReceiver() { // filter specifies which event Receiver should listen to IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_SERVICE_DESTROYED); - getActivity().registerReceiver(new TripEndReceiver(), filter); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE){ + getActivity().registerReceiver(new TripEndReceiver(), filter, Context.RECEIVER_NOT_EXPORTED); + }else{ + getActivity().registerReceiver(new TripEndReceiver(), filter); + } } /**