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 :)
React Native combines the best parts of native development with React, a best-in-class JavaScript library for building user interfaces. Use a little—or a lot. You can use React Native today in your existing Android and iOS projects or you can create a whole new app from scratch.
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:
Linking
from react-native
AndroidOpenSettings
from react-native-android-open-settings
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>
);
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With