問題描述
我一直在嘗試將 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 設備位置的權限?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!