[英]Flutter - Android doesn't ask for permissions
我正在嘗試使用插件位置獲取設備的當前位置,但 Android 從不請求權限。 我收到此錯誤:
發生異常。 PlatformException(PlatformException(PERMISSION_DENIED_NEVER_ASK,位置權限永遠被拒絕-請打開應用程序設置,null))
我在 Android 文件夾中可以找到的每個“AndroidManifest.xml”文件中添加了以下行(不知道我應該實際使用哪個,我找到了其中的 3 個)
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我嘗試了插件permission_handler手動請求它們,但仍然沒有彈出窗口。
我完全迷路了,我在網上找不到類似的東西。 這是代碼:
Future<LocationData> _getLocation() async {
LocationData currentLocation;
// returns a map with unreadable numbers which make no sense
var t = await PermissionHandler()
.requestPermissions([PermissionGroup.location]);
// returns false
var test = await location.requestPermission();
try {
currentLocation = await location.getLocation();
} catch (e) {
currentLocation = null;
}
return currentLocation;
}
編輯:我在我的設備(OnePlus 6)和模擬器(Pixel XL API 28)上嘗試了這個。 我也嘗試卸載/重新安裝該應用程序。
我正在嘗試使用插件位置獲取設備的當前位置,但Android從未要求獲得權限。 我收到此錯誤:
發生異常。 PlatformException(PlatformException(PERMISSION_DENIED_NEVER_ASK,位置權限被永久拒絕-請打開應用設置,為null))
我在Android文件夾中可以找到的每個“ AndroidManifest.xml”文件中添加了以下行(不知道我應該實際使用哪一個,我發現了其中的3個)
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我嘗試了插件permission_handler手動請求它們,但仍然沒有彈出窗口。
我完全迷路了,網上找不到任何類似的東西。 這是代碼:
Future<LocationData> _getLocation() async {
LocationData currentLocation;
// returns a map with unreadable numbers which make no sense
var t = await PermissionHandler()
.requestPermissions([PermissionGroup.location]);
// returns false
var test = await location.requestPermission();
try {
currentLocation = await location.getLocation();
} catch (e) {
currentLocation = null;
}
return currentLocation;
}
編輯:我在我的設備(OnePlus 6)和仿真器(Pixel XL API 28)上嘗試了此操作。 我也嘗試過卸載/重新安裝該應用程序。
我正在嘗試使用插件位置獲取設備的當前位置,但Android從未要求獲得權限。 我收到此錯誤:
發生異常。 PlatformException(PlatformException(PERMISSION_DENIED_NEVER_ASK,位置權限被永久拒絕-請打開應用設置,為null))
我在Android文件夾中可以找到的每個“ AndroidManifest.xml”文件中添加了以下行(不知道我應該實際使用哪一個,我發現了其中的3個)
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我嘗試了插件permission_handler手動請求它們,但仍然沒有彈出窗口。
我完全迷路了,網上找不到任何類似的東西。 這是代碼:
Future<LocationData> _getLocation() async {
LocationData currentLocation;
// returns a map with unreadable numbers which make no sense
var t = await PermissionHandler()
.requestPermissions([PermissionGroup.location]);
// returns false
var test = await location.requestPermission();
try {
currentLocation = await location.getLocation();
} catch (e) {
currentLocation = null;
}
return currentLocation;
}
編輯:我在我的設備(OnePlus 6)和仿真器(Pixel XL API 28)上嘗試了此操作。 我也嘗試過卸載/重新安裝該應用程序。
我正在嘗試使用插件位置獲取設備的當前位置,但Android從未要求獲得權限。 我收到此錯誤:
發生異常。 PlatformException(PlatformException(PERMISSION_DENIED_NEVER_ASK,位置權限被永久拒絕-請打開應用設置,為null))
我在Android文件夾中可以找到的每個“ AndroidManifest.xml”文件中添加了以下行(不知道我應該實際使用哪一個,我發現了其中的3個)
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我嘗試了插件permission_handler手動請求它們,但仍然沒有彈出窗口。
我完全迷路了,網上找不到任何類似的東西。 這是代碼:
Future<LocationData> _getLocation() async {
LocationData currentLocation;
// returns a map with unreadable numbers which make no sense
var t = await PermissionHandler()
.requestPermissions([PermissionGroup.location]);
// returns false
var test = await location.requestPermission();
try {
currentLocation = await location.getLocation();
} catch (e) {
currentLocation = null;
}
return currentLocation;
}
編輯:我在我的設備(OnePlus 6)和仿真器(Pixel XL API 28)上嘗試了此操作。 我也嘗試過卸載/重新安裝該應用程序。
添加這個
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.