From f72026ee9fee85705ce8c9cd1bfb75bb6c2ef2e5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 23 Dec 2025 02:41:47 +0000 Subject: [PATCH 1/3] Update Android background location permission flow for API 30+ - Implement special handling for `ACCESS_BACKGROUND_LOCATION` on API >= 30 in `AndroidImplementation.java`. - Bypass `ActivityCompat.requestPermissions` and guide users to Settings. - Add localization keys for new dialog strings. - Update developer guide with instructions on new behavior and build hint requirements. --- .../impl/android/AndroidImplementation.java | 30 +++++++++++++++++++ .../Miscellaneous-Features.asciidoc | 8 +++++ 2 files changed, 38 insertions(+) diff --git a/Ports/Android/src/com/codename1/impl/android/AndroidImplementation.java b/Ports/Android/src/com/codename1/impl/android/AndroidImplementation.java index 45acab0480..0006c35747 100644 --- a/Ports/Android/src/com/codename1/impl/android/AndroidImplementation.java +++ b/Ports/Android/src/com/codename1/impl/android/AndroidImplementation.java @@ -10898,6 +10898,36 @@ public static boolean checkForPermission(String permission, String description, if(android.os.Build.VERSION.SDK_INT < 23){ return true; } + + if (android.os.Build.VERSION.SDK_INT >= 30 && "android.permission.ACCESS_BACKGROUND_LOCATION".equals(permission)) { + if (android.support.v4.content.ContextCompat.checkSelfPermission(getContext(), permission) == PackageManager.PERMISSION_GRANTED) { + return true; + } + if (getActivity() == null) { + return false; + } + + String prompt = Display.getInstance().getProperty(permission, description); + String title = Display.getInstance().getProperty("android.permission.ACCESS_BACKGROUND_LOCATION.title", "Requires permission"); + String settingsBtn = Display.getInstance().getProperty("android.permission.ACCESS_BACKGROUND_LOCATION.settings", "Settings"); + String cancelBtn = Display.getInstance().getProperty("android.permission.ACCESS_BACKGROUND_LOCATION.cancel", "Cancel"); + + if(Dialog.show(title, prompt, settingsBtn, cancelBtn)){ + Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + Uri uri = Uri.fromParts("package", getContext().getPackageName(), null); + intent.setData(uri); + getActivity().startActivity(intent); + + String explanationTitle = Display.getInstance().getProperty("android.permission.ACCESS_BACKGROUND_LOCATION.explanation_title", "Permission Required"); + String explanationBody = Display.getInstance().getProperty("android.permission.ACCESS_BACKGROUND_LOCATION.explanation_body", "Please enable 'Allow all the time' in the settings, then press OK."); + String okBtn = Display.getInstance().getProperty("android.permission.ACCESS_BACKGROUND_LOCATION.ok", "OK"); + + Dialog.show(explanationTitle, explanationBody, okBtn, null); + return android.support.v4.content.ContextCompat.checkSelfPermission(getActivity(), permission) == PackageManager.PERMISSION_GRANTED; + } else { + return false; + } + } String prompt = Display.getInstance().getProperty(permission, description); diff --git a/docs/developer-guide/Miscellaneous-Features.asciidoc b/docs/developer-guide/Miscellaneous-Features.asciidoc index e12d071ecc..f5d235e776 100644 --- a/docs/developer-guide/Miscellaneous-Features.asciidoc +++ b/docs/developer-guide/Miscellaneous-Features.asciidoc @@ -450,6 +450,14 @@ LocationManager.getLocationManager() .addGeoFencing(GeofenceListenerImpl.class, gf); ---- +===== Android Background Location Permissions (API 30+) + +On Android 11 (API level 30) and higher, requesting background location permission requires a two-step process. First, foreground location permissions must be granted. Then, the app must request background location access, which will direct the user to the system settings to select "Allow all the time". + +Codename One handles this flow automatically when you use `LocationManager`. If your app targets Android 10 (API level 29) or higher, you can enable the background permission request by setting the build hint `android.requiresBackgroundLocationPermissionForAPI29=true`. + +For API 30+, Codename One detects if background location is needed and presents a dialog explaining the requirement before redirecting the user to the app settings. You can customize the permission prompt message using the localization key `android.permission.ACCESS_BACKGROUND_LOCATION`. + [source,java] ---- public class GeofenceListenerImpl implements GeofenceListener { From e7d1885f5ca3e1d4e1784da1720cdf1a218caccb Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 23 Dec 2025 03:12:28 +0000 Subject: [PATCH 2/3] Update Android background location permission flow for API 30+ - Implement special handling for `ACCESS_BACKGROUND_LOCATION` on API >= 30 in `AndroidImplementation.java`. - Bypass `ActivityCompat.requestPermissions` and guide users to Settings. - Add localization keys for new dialog strings. - Update developer guide with instructions on new behavior and build hint requirements. --- docs/developer-guide/Miscellaneous-Features.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/developer-guide/Miscellaneous-Features.asciidoc b/docs/developer-guide/Miscellaneous-Features.asciidoc index f5d235e776..8cbee3dc43 100644 --- a/docs/developer-guide/Miscellaneous-Features.asciidoc +++ b/docs/developer-guide/Miscellaneous-Features.asciidoc @@ -454,9 +454,9 @@ LocationManager.getLocationManager() On Android 11 (API level 30) and higher, requesting background location permission requires a two-step process. First, foreground location permissions must be granted. Then, the app must request background location access, which will direct the user to the system settings to select "Allow all the time". -Codename One handles this flow automatically when you use `LocationManager`. If your app targets Android 10 (API level 29) or higher, you can enable the background permission request by setting the build hint `android.requiresBackgroundLocationPermissionForAPI29=true`. +Codename One handles this flow automatically when you use `LocationManager`. You can enable the background permission request by setting the build hint `android.requiresBackgroundLocationPermissionForAPI29=true`. -For API 30+, Codename One detects if background location is needed and presents a dialog explaining the requirement before redirecting the user to the app settings. You can customize the permission prompt message using the localization key `android.permission.ACCESS_BACKGROUND_LOCATION`. +For Android 11+ (API 30+), Codename One detects if background location is needed and presents a dialog explaining the requirement before redirecting the user to the app settings. You can customize the permission prompt message using the localization key `android.permission.ACCESS_BACKGROUND_LOCATION`. [source,java] ---- From 810f330733707ef36eb8d58e443d4426ac49bd79 Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Tue, 23 Dec 2025 05:17:03 +0200 Subject: [PATCH 3/3] Update Android background location permissions section Clarified the process for requesting background location permissions on Android 11 and higher, including details about Codename One's handling of the flow and customization options. --- docs/developer-guide/Miscellaneous-Features.asciidoc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/developer-guide/Miscellaneous-Features.asciidoc b/docs/developer-guide/Miscellaneous-Features.asciidoc index 8cbee3dc43..f15e391d14 100644 --- a/docs/developer-guide/Miscellaneous-Features.asciidoc +++ b/docs/developer-guide/Miscellaneous-Features.asciidoc @@ -452,9 +452,7 @@ LocationManager.getLocationManager() ===== Android Background Location Permissions (API 30+) -On Android 11 (API level 30) and higher, requesting background location permission requires a two-step process. First, foreground location permissions must be granted. Then, the app must request background location access, which will direct the user to the system settings to select "Allow all the time". - -Codename One handles this flow automatically when you use `LocationManager`. You can enable the background permission request by setting the build hint `android.requiresBackgroundLocationPermissionForAPI29=true`. +On Android 11 (API level 30) and higher, requesting background location permission requires a two-step process. First, foreground location permissions must be granted. Then, the app must request background location access, which will direct the user to the system settings to select "Allow all the time". Codename One handles this flow automatically when you use `LocationManager`. For Android 11+ (API 30+), Codename One detects if background location is needed and presents a dialog explaining the requirement before redirecting the user to the app settings. You can customize the permission prompt message using the localization key `android.permission.ACCESS_BACKGROUND_LOCATION`.