Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added open location source settings support #443

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| --- | --- | --- |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ declare module "react-native-geolocation-service" {
export function clearWatch(watchID: number): void;

export function stopObserving(): void;

export function openLocationSourceSettings(): void;
}
4 changes: 4 additions & 0 deletions js/Geolocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
};

Expand Down
8 changes: 8 additions & 0 deletions js/Geolocation.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ const Geolocation = {

subscriptions = [];
}
},

openLocationSourceSettings: () => {
if (Platform.OS === 'ios') {
console.warn('OpenLocationSourceSettings not supported on IOS');
} else {
RNFusedLocation.openLocationSourceSettings();
}
}
};

Expand Down