How do I request permission for Android Device Location in React Native at run-time?(如何在运行时在 React Native 中请求 Android 设备位置的权限?)
问题描述
我一直在尝试将 React Native 的 GeoLocalisation 用于 Android 应用程序.文档记录不佳的模块可在此处找到 https://facebook.github.io/react-本机/docs/geolocation.html.根据文档,您使用 AndroidManifest.xml 文件中的以下代码处理 Android 上的位置权限
I have been trying to use React Native 's GeoLocalisation for an Android App. The poorly documentated module is found here https://facebook.github.io/react-native/docs/geolocation.html.
According to the documentation, you handle location permissions on Android using the following code in the AndroidManifest.xml file
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
但是,我的在线研究表明,上述代码行对于 ANDROID >= 6.0
However, my online research suggests that the above line of code is useless for versions of ANDROID >= 6.0
由于我的 GeoLocation 实现当前无法正常工作,我没有其他理由相信位置权限没有得到正确处理.
As my implementation of GeoLocation is not currently working, I have no other reason but to believe that location permissions are not correctly handled.
如何在运行时为 React Native Android App 成功请求位置权限?提前致谢!
How do I successfully request location permission at run-time for React Native Android App ? Thanks in advance !
推荐答案
这对我不起作用
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
}
我提到了 https://facebook.github.io/react-native/docs/permissionsandroid.html#request并且 check() 返回一个布尔值
I referred to https://facebook.github.io/react-native/docs/permissionsandroid.html#request and check() return a boolean
const granted = await PermissionsAndroid.check( PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION );
if (granted) {
console.log( "You can use the ACCESS_FINE_LOCATION" )
}
else {
console.log( "ACCESS_FINE_LOCATION permission denied" )
}
这篇关于如何在运行时在 React Native 中请求 Android 设备位置的权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在运行时在 React Native 中请求 Android 设备位置
基础教程推荐
- 如何将多个组件添加到 PickerView? 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 我的 UIImageView 的任务 2022-01-01
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
- Android:STATE_SELECTED不工作 2022-01-01
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
