Vinay Sharma
Vinay Sharma

Reputation: 3797

React Native: How to open OS settings in Android and iOS?

I am developing a mobile application using React Native in which I want to open mobile device's settings when user clicks on a specific button.

I have gone through the docs of RN, but still couldn’t find anything that can help me in achieving the same. Can someone guide me on the same, how can that be implemented?

Thanks :)

Upvotes: 10

Views: 12906

Answers (4)

SmileYang966
SmileYang966

Reputation: 41

You can try the below code, "android.settings.SETTINGS" which can help you jump to the os setting screen.

import {Linking } from 'react-native'
Linking.sendIntent("android.settings.SETTINGS");

Upvotes: 4

A.Kraus
A.Kraus

Reputation: 358

As an addition to Rafael Perozin's answer.

On Android you can also send an Intent via Linking.

import { Button, Linking } from "react-native";

const Screen = () => (
  <Button
    title="Open Settings"
      onPress={() => {
      Platform.OS === 'ios' 
        ? Linking.openURL('App-Prefs:Bluetooth')
        : Linking.sendIntent("android.settings.BLUETOOTH_SETTINGS");
    }}
  />
);

Upvotes: 18

Rafael Perozin
Rafael Perozin

Reputation: 663

In my case I would like to send the user to Bluetooth settings and the CR7 answer didn't work for me.

So, I solved the problem using:

And I also used the Platform from react-native to check if the current device is an IOS.

See the code:

...
import {Linking, Platform} from 'react-native';
import AndroidOpenSettings from 'react-native-android-open-settings';
...

...
const goToSettings = () =>
  Platform.OS === 'ios'
    ? Linking.openURL('App-Prefs:Bluetooth')
    : AndroidOpenSettings.bluetoothSettings();
...

...
return (
<TouchableOpacity onPress={() => goToSettings()}>
  <Text>Go to settings</Text>
</TouchableOpacity>
);
...

Upvotes: 7

CR7
CR7

Reputation: 587

Did you try to use Linking component form react-native (v0.60+)?

import { Button, Linking } from "react-native";

const Screen = () => (
  <Button
    title="Open Settings"
    onPress={() => {
      Linking.openSettings();
    }}
  />
);

Upvotes: -4

Related Questions