Open your apps settings in the Settings app :P
npm install et3arraf/rnosl
or yarn add et3arraf/rnosl
Add React Native Open Settings
to project libraries.
- Edit
build.gradle
to look like this:
apply plugin: 'com.android.application'
android {
...
}
dependencies {
...
+ compile project(':react-native-open-settings')
}
- In
settings.gradle
, insert the following code:
include ':react-native-open-settings'
project(':react-native-open-settings').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-open-settings/android')
- Edit your
MainActivity.java
to look like this:
package com.myapp;
....
import com.opensettings.OpenSettingsPackage
public class MainActivity extends extends ReactActivity {
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new OpenSettingsPackage()
);
}
...
}
Require the react-native-open-settings
module.
import OpenSettings from 'react-native-open-settings';
And then, where you want to open the settings, just do
// Check if location is enabled
OpenSettings.isLocationEnabled().then((isLocationEnabled) => {
//isLocationEnabled is a boolean
})
// Open app permissions page
OpenSettings.openAppPermissionsSettings()
// Open location settings page
OpenSettings.openLocationSettings()
// Very fast country grabbing from locale settings
OpenSettings.getCountryCode().then((countryCode) => {
console.log(countryCode); // OUTPUT : US or LB or ...
})
// Very fast location grabbing. returns "none" if lastKnown result is null
OpenSettings.getLastKnownLocation().then((result) => {
console.log(result);
})
Have fun!