首页 > 解决方案 > 如何访问我的 react-native expo 应用程序的位置权限设置?

问题描述

我知道我们可以使用访问某些 android 设置IntentLauncherAndroid

我目前的代码如下:

import { IntentLauncherAndroid as IntentLauncher } from 'expo';

// onClick function to access app's permission settings
onPressButton = () => {
  IntentLauncher.startActivityAsync(IntentLauncher.ACTION_SETTINGS)
}

虽然目前该按钮仅打开手机的常规设置。

标签: react-nativeexpo

解决方案


此代码应该是您想要的,您可以使用 Intent Promise 来了解用户何时从 Intent 操作返回(https://docs.expo.io/versions/latest/sdk/intent-launcher/#returns

import { IntentLauncherAndroid as IntentLauncher } from 'expo';

// onClick function to access app's permission settings
onPressButton = async () => {
  const intent = await IntentLauncher.startActivityAsync(
    IntentLauncher.ACTION_LOCATION_SOURCE_SETTINGS
  )
}

推荐阅读