我试图在我的离子型应用程序上使用API级别29,我要求应用程序要求用户提供“允许任何时间”的位置。我把所有建议的修改都加进去了。
我的AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION">
<uses-permission android:name="android.permission.PERMISSION.FOREGROUND_SERVICE">我的app.component.ts:
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
this.setProviders();
this.checkBackgroundPermission();
});
}
private async checkBackgroundPermission() {
try {
const result = await this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.ACCESS_BACKGROUND_LOCATION);
if (!result || result.hasPermission === false) {
this.requestPermissions();
}
} catch (error) {
this.requestPermissions();
}
}
private async requestPermissions() {
try {
const data = await this.androidPermissions.requestPermissions([
this.androidPermissions.PERMISSION.ACCESS_BACKGROUND_LOCATION,
this.androidPermissions.PERMISSION.ACCESS_COARSE_LOCATION,
this.androidPermissions.PERMISSION.ACCESS_FINE_LOCATION,
this.androidPermissions.PERMISSION.ACTIVITY_RECOGNITION,
this.androidPermissions.PERMISSION.FOREGROUND_SERVICE
]);
if (!data.hasPermission) {
throw new Error('No permission');
}
} catch (error) {
await this.alertService.showAlert(
'Background location',
'We need background location access in order to continue.'
);
this.signOut();
}然而,当我以Api 29为目标时,它并不总是显示允许位置的请求。

但是如果我使用Api级别28,它会显示我需要的权限。
对此有什么建议吗?
发布于 2022-02-14 23:51:27
将这个添加到platforms\android\app\src\main\AndroidManifest.xml中
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />Geolocation.java文件中的更改(地理定位)
String [] permissions = { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION }String [] permissions = { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION };https://stackoverflow.com/questions/63676512
复制相似问题