From 9cb0cb42264cbb3c5e3cd5467143c668f2c7075c Mon Sep 17 00:00:00 2001 From: pinpong Date: Mon, 2 Dec 2024 08:04:51 +0100 Subject: [PATCH] added open location source settings support --- README.md | 3 +++ .../RNFusedLocation/RNFusedLocationModule.java | 12 ++++++++++++ index.d.ts | 2 ++ js/Geolocation.js | 4 ++++ js/Geolocation.native.js | 8 ++++++++ 5 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 81c5a66..58ec8a7 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,9 @@ When promise resolves, returns the status of the authorization. #### `stopObserving()` Stops observing for device location changes. In addition, it removes all listeners previously registered. +#### `openLocationSourceSettings()` +Open Location source settings (android only). + # Error Codes | Name | Code | Description | | --- | --- | --- | diff --git a/android/src/main/java/com/agontuk/RNFusedLocation/RNFusedLocationModule.java b/android/src/main/java/com/agontuk/RNFusedLocation/RNFusedLocationModule.java index 414e2be..b7be870 100644 --- a/android/src/main/java/com/agontuk/RNFusedLocation/RNFusedLocationModule.java +++ b/android/src/main/java/com/agontuk/RNFusedLocation/RNFusedLocationModule.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.content.Intent; import android.location.Location; +import android.provider.Settings; import android.util.Log; import androidx.annotation.NonNull; @@ -141,6 +142,17 @@ public void stopObserving() { } } + @ReactMethod + public void openLocationSourceSettings() { + ReactApplicationContext context = getContext(); + Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); + if (intent.resolveActivity(context.getPackageManager()) != null) { + context.startActivity(intent); + } + } + @ReactMethod public void addListener(String eventName) { // Keep: Required for RN built in Event Emitter Calls. diff --git a/index.d.ts b/index.d.ts index 313049e..137b3ff 100644 --- a/index.d.ts +++ b/index.d.ts @@ -96,4 +96,6 @@ declare module "react-native-geolocation-service" { export function clearWatch(watchID: number): void; export function stopObserving(): void; + + export function openLocationSourceSettings(): void; } diff --git a/js/Geolocation.js b/js/Geolocation.js index 3fc7eba..bc8f0ab 100644 --- a/js/Geolocation.js +++ b/js/Geolocation.js @@ -40,6 +40,10 @@ const Geolocation = { stopObserving: function () { throw new Error('Method not supported by browser'); + }, + + openLocationSourceSettings: function () { + throw new Error('Method not supported by browser'); } }; diff --git a/js/Geolocation.native.js b/js/Geolocation.native.js index 89ccb4f..3d2f6bf 100644 --- a/js/Geolocation.native.js +++ b/js/Geolocation.native.js @@ -108,6 +108,14 @@ const Geolocation = { subscriptions = []; } + }, + + openLocationSourceSettings: () => { + if (Platform.OS === 'ios') { + console.warn('OpenLocationSourceSettings not supported on IOS'); + } else { + RNFusedLocation.openLocationSourceSettings(); + } } };