Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open application's location permission settings directly in React Native

REACTNATIVE : Currently using Linking.openSettings() to open my application settings page.

Now, I want to open the app permission screen directly, which is inside the App settings to enable permissions like Location, Storage etc., in both Android and iOS using REACT NATIVE.

Any possibilities? Thanks in advance!

like image 663
Eshack Nazir Avatar asked Nov 10 '20 13:11

Eshack Nazir


People also ask

How do I get location permissions in React Native?

Geolocation is enabled by default when you create a project with react-native init . In order to enable geolocation in the background, you need to include the 'NSLocationAlwaysUsageDescription' key in Info. plist and add location as a background mode in the 'Capabilities' tab in Xcode.

How do I ask permission in React Native?

MainApplication" android:label="@string/app_name" ..... ..... So to integrate the permissions in our react native code, you can refer to the below code. After importing the necessary package, we can ask the user permission with PermissionsAndroid. request() method.


1 Answers

Shortly it's possible,

For IOS operating system, Try below,

import { Linking } from 'react-native'
Linking.openURL('app-settings:')

But Android not working with Linking,We should add two dependency,

npm install --save react-native-device-info

npm install react-native-intent-launcher

As a result,

import DeviceInfo from 'react-native-device-info';
import IntentLauncher, { IntentConstant } from 'react-native-intent-launcher'
const package= DeviceInfo.getBundleId();
const openAppSettings = () => {
  if (Platform.OS === 'ios') {
    Linking.openURL('app-settings:')
  } else {
    IntentLauncher.startActivity({
      action: 'android.settings.APPLICATION_DETAILS_SETTINGS',
      data: 'package:' + package
    })
  }
}
like image 159
Onur Ozdemir Avatar answered Sep 30 '22 10:09

Onur Ozdemir