简体   繁体   English

Android Studio 忽略清单使用权限条目

[英]Android Studio ignoring Manifest uses-permission entries

I am trying to show my location on a GoogleMap but Android Studio reports a fatal error on the following line我试图在 GoogleMap 上显示我的位置,但 Android Studio 在以下行报告了一个致命错误

savedGoogleMap.isMyLocationEnabled = true

The error message is错误信息是

Missing permissions required by GoogleMap.setMyLocationEnabled: android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION缺少 GoogleMap.setMyLocationEnabled 所需的权限:android.permission.ACCESS_COARSE_LOCATION 或 android.permission.ACCESS_FINE_LOCATION

The problem is the manifest file already includes both permissions so they are not missing!问题是清单文件已经包含这两个权限,所以它们不会丢失!

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Using the IDE context actions to add the permissions inserts additional .ACCESS___LOCATION to the manifest file but Android Studio still reports the fatal error使用 IDE 上下文操作添加权限会向清单文件插入额外的 .ACCESS___LOCATION 但 Android Studio 仍然报告致命错误

The apparent issue is Android Studio is ignoring permissions included in the manifest明显的问题是 Android Studio 忽略清单中包含的权限

Earlier posts eg here highlight the need for runtime permission checks早期的帖子,例如此处强调了运行时权限检查的必要性

My App checks for the required permissions and if checkSelfPermission is not granted I then request the required permissions我的应用程序检查所需的权限,如果未授予 checkSelfPermission,我会请求所需的权限

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)

So at this moment my app shows a fatal error but there appears no way to fix it所以此时我的应用程序显示了一个致命错误,但似乎没有办法修复它

Can anyone suggest other avenues I might try?谁能建议我可以尝试的其他途径?

Update更新

Despite the fatal error the App builds and launches?尽管应用程序构建和启动时出现致命错误? It also shows myLocation on the Google map.它还在 Google map 上显示 myLocation。

My problem is the manifest file already includes both permissions!我的问题是清单文件已经包含这两个权限!

That's not the problem.那不是问题。 It is totally fine to have both permissions declared in your AndroidManifest.xml file, just make sure they are added in the correct place like so在您的 AndroidManifest.xml 文件中声明这两个权限是完全没问题的,只需确保将它们添加到正确的位置,就像这样声明权限

After you double checked on that one, make sure you you not only call checkSelfPermission, but also requestPermissions like this:在仔细检查那个之后,确保你不仅调用了 checkSelfPermission,还调用了 requestPermissions,如下所示: 请求权限

After receiving the result proceed with your calls (or if the permission was already granted).收到结果后继续你的电话(或者如果权限已经被授予)。

If you are positive with this so far and still no success, it would seem to me that something else is causing the problem and I would look into the configuration files, library dependency, caches etc.如果到目前为止您对此持肯定态度但仍然没有成功,那么在我看来是其他原因导致了问题,我会查看配置文件、库依赖项、缓存等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Studio 无法识别 AndroidManifest 中的使用权限 - Android Studio not recognizing uses-permission in the AndroidManifest <uses-permission> 与 <permission> 在Android 6.0中的Manifest.xml - <uses-permission> vs <permission> in Android 6.0 Manifest.xml Visual Studio 2019 Android - 意外元素<uses-permission>在发现<manifest><application></application></manifest></uses-permission> - Visual studio 2019 Android - unexpected element <uses-permission> found in <manifest><application> 使用许可 android - uses-permission android Android 23不生成用户权限元素的清单文件 - Android 23 Not Generating Manifest file for uses-permission elements 的角色 <uses-permission> 清单文件中标记? - Role of <uses-permission> tag in manifest file? Android使用权限供以后使用 - Android uses-permission for later 如何在 Android Studio 中解决(错误:不支持的类型“使用权限”)? - How to resolve (Error: Unsupported type 'uses-permission') in Android Studio? android:uses-permission和uses-permission有什么区别? - What is the difference between android:uses-permission and uses-permission? 包含 <uses-permission android:name=“android.permission.INTERNET” /> 在清单中导致错误 - including <uses-permission android:name=“android.permission.INTERNET” /> in manifest causes error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM