34

At the end react native bridge is the only way.But is there any npm package which has been worked successfully for anyone?

0

8 Answers 8

55

You can open your app settings by using Linking library.

import {Linking} from 'react-native';

Linking.openSettings();

Offical document: https://reactnative.dev/docs/linking#opensettings

Sign up to request clarification or add additional context in comments.

6 Comments

It is not working for me(Property 'openSettings' does not exist on type 'LinkingStatic'.)
Are you using TypeScript?
If you're using expo it will not work, for expo: docs.expo.io/versions/latest/workflow/linking
openSettings() works with react-native 59.0 and above. Maybe your react-native version not enought to use the method. The error comes from TypeScript by the way.
I am using react native version 0.60.But anyways openSettings() has worked for me fine.
|
20

You can use @react-native-community/react-native-permissions library.

Here offical documantation: https://github.com/react-native-community/react-native-permissions#opensettings

Example:

import { openSettings } from 'react-native-permissions';
openSettings();

2 Comments

Can open without using an additional library, see below - Linking.openSettings()
Hey, this works quite well, but i want user to give permissions manually by going into app settings. but when app settings are opened using the method you gave, after giving permissions manually and going back to the application, it does not get rerendered or get updates witht the permission. i need to go to some another screen aand after comming back to this screen will then update the permissions for the app. please help
20

combining the existing answers: this works for me for both iOS and Android (without expo)

import { Linking, Platform } from 'react-native';


const handleOpenSettings = () => {
    if (Platform.OS === 'ios') {
      Linking.openURL('app-settings:');
    } else {
      Linking.openSettings();
    }
};

// add a button that calls handleOpenSetttings()

1 Comment

Works for me in Expo (v47.0.3)
14

Linking API from react-native core provides the function to send custom intent action to Android.

NOTE - You can send any custom action that is acceptable by android, moreover you can also pass data to the intent.

You can find more keys at developer.android.com/reference/android/provider/Settings.

Here is an example to open settings :

import {Linking} from 'react-native';

// To open settings
Linking.sendIntent('android.settings.SETTINGS');

// To open GPS Location setting
Linking.sendIntent('android.settings.LOCATION_SOURCE_SETTINGS');

Hope this will help you or somebody else. Thanks!

Happy Coding :-)

4 Comments

Much thanks was looking for LOCATION_SOURCE_SETTINGS key.
@FazalKarim Happy to know that it helped you.
You can find more keys at developer.android.com/reference/android/provider/Settings. If the key asks for an "Input", invoke sendIntent with an argument like [{ key: inputConstantValue, value: value }]. For example, to open the notifications settings for my app, I did Linking.sendIntent('android.settings.APP_NOTIFICATION_SETTINGS', [{ key: 'android.provider.extra.APP_PACKAGE', value: 'com.mpeschel10.example' }]);
thanks @MarkPeschel, i created a variable to set the value: const appId = Application.applicationId. I had to import this: import * as Application from "expo-application"; and then Linking.sendIntent('android.settings.APP_NOTIFICATION_SETTINGS', [{ key: 'android.provider.extra.APP_PACKAGE', value: appId }]);
4

Use

IntentLauncher.startActivity({
  action: 'android.settings.SETTINGS',
})

instead of

IntentLauncher.startActivity({
  action: 'android.settings.APPLICATION_DETAILS_SETTINGS',
  data: 'package:' + pkg
})

Like

import IntentLauncher, { IntentConstant } from 'react-native-intent-launcher'
const openAppSettings = () => {
  if (Platform.OS === 'ios') {
    Linking.openURL('app-settings:')
  } else {
    IntentLauncher.startActivity({
      action: 'android.settings.SETTINGS',
    })
  }
}

ANDROID

Wifi

IntentLauncher.startActivity({
 action: 'android.settings.SETTINGS'
})

GPS

IntentLauncher.startActivity({
 action: 'android.settings.LOCATION_SOURCE_SETTINGS'
})

IOS

WIFI

Linking.openURL("App-Prefs:root=WIFI");

GPS

Linking.openURL('App-Prefs:Privacy&path=LOCATION')

Comments

2

This is a complete answer for both android & iOS.

Without Expo:

import DeviceInfo from 'react-native-device-info';
import IntentLauncher, { IntentConstant } from 'react-native-intent-launcher'
const pkg = DeviceInfo.getBundleId();
const openAppSettings = () => {
  if (Platform.OS === 'ios') {
    Linking.openURL('app-settings:')
  } else {
    IntentLauncher.startActivity({
      action: 'android.settings.APPLICATION_DETAILS_SETTINGS',
      data: 'package:' + pkg
    })
  }
}

With Expo:

import Constants from 'expo-constants'
import * as IntentLauncher from 'expo-intent-launcher'
const pkg = Constants.manifest.releaseChannel
? Constants.manifest.android.package 
: 'host.exp.exponent'
const openAppSettings = () => {
  if (Platform.OS === 'ios') {
    Linking.openURL('app-settings:')
  } else {
    IntentLauncher.startActivityAsync(
      IntentLauncher.ACTION_APPLICATION_DETAILS_SETTINGS,
      { data: 'package:' + pkg },
    )
  }
}

Comments

0
import React, { useCallback } from "react";
import { Button, Linking, StyleSheet, View } from "react-native";

const OpenSettingsButton = ({ children }) => {
  const handlePress = useCallback(async () => {
    // Open the custom settings if the app has one
    await Linking.openSettings();
  }, []);

  return <Button title={children} onPress={handlePress} />;
};

const App = () => {
  return (
    <View style={styles.container}>
      <OpenSettingsButton>Open Settings</OpenSettingsButton>
    </View>
  );
};

const styles = StyleSheet.create({
  container: { flex: 1, justifyContent: "center", alignItems: "center" },
});

Comments

0
  import { Linking, Platform } from 'react-native';

   

    const openSettingsAlert = () =>
            Alert.alert('Please provide the require permission from settings', '', [
              {
                text: 'Cancel',
                onPress: () => console.log('Cancel Pressed'),
                style: 'cancel',
              },
              { text: 'Go To Settings', onPress: () => openSettings() },
            ]);



  

    const openSettings = () => {
        if (Platform.OS === 'ios') {
          Linking.openURL('app-settings:');
        } else {
          Linking.openSettings();
        }
      };




    let isStoragePermitted = await requestExternalWritePermission();
            if (isStoragePermitted === true) {
              
            }else{
              console.log('permission not granted');
              openSettingsAlert();
            }







    const requestExternalWritePermission = async () => {
        if (Platform.OS === 'android') {
          try {
            const granted = await PermissionsAndroid.request(
              PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
            );
            // If WRITE_EXTERNAL_STORAGE Permission is granted
            return granted === PermissionsAndroid.RESULTS.GRANTED;
          } catch (err) {
            console.warn(err);
            alert('Storage Access permission error:', err);
          }
          return false;
        }
      };

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.