問題描述
我一直在嘗試將 React Native 的 GeoLocalisation 用于 Android 應(yīng)用程序.文檔記錄不佳的模塊可在此處找到 https://facebook.github.io/react-本機(jī)/docs/geolocation.html.根據(jù)文檔,您使用 AndroidManifest.xml
文件中的以下代碼處理 Android 上的位置權(quán)限
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" />
但是,我的在線研究表明,上述代碼行對(duì)于 ANDROID >= 6.0
However, my online research suggests that the above line of code is useless for versions of ANDROID >= 6.0
由于我的 GeoLocation 實(shí)現(xiàn)當(dāng)前無法正常工作,我沒有其他理由相信位置權(quán)限沒有得到正確處理.
As my implementation of GeoLocation is not currently working, I have no other reason but to believe that location permissions are not correctly handled.
如何在運(yùn)行時(shí)為 React Native Android App 成功請(qǐng)求位置權(quán)限?提前致謝!
How do I successfully request location permission at run-time for React Native Android App ? Thanks in advance !
推薦答案
這對(duì)我不起作用
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
}
我提到了 https://facebook.github.io/react-native/docs/permissionsandroid.html#request并且 check() 返回一個(gè)布爾值
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" )
}
這篇關(guān)于如何在運(yùn)行時(shí)在 React Native 中請(qǐng)求 Android 設(shè)備位置的權(quán)限?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!