简体   繁体   English

根据用户 Android 版本区分请求的 Android 权限

[英]Make distinction in requested Android permissions based on the users Android version

I have created an app which amongs others show the SSID name.我创建了一个应用程序,其中显示 SSID 名称。 Now with the latest android version, the user needs to set extra permissions ( <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> ) for my app to be able to get the SSID name.现在使用最新的 android 版本,用户需要为我的应用设置额外的权限( <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> )才能获取 SSID 名称。

Now that's all fine, but 1. these permissions are harder to get (I understand that I can't just ask for them but the user has to explicit go to the app-settings and accept the location permission) and, more importantly 2. I don't want to ask for those rights if the user is still on an old(er) version of Android and these extra permissions are not needed.现在一切都很好,但是 1. 这些权限更难获得(我知道我不能只要求它们,但用户必须明确转到应用程序设置并接受位置权限),更重要的是 2.如果用户仍在使用旧(较)版本的 Android 并且不需要这些额外权限,我不想要求这些权限。

I have these settings我有这些设置

minSdkVersion 11
targetSdkVersion 26

so also very old Android versions can install my app, and now they also have to give the permission for the Android version they don't yet have?所以非常旧的Android版本也可以安装我的应用程序,现在他们还必须授予他们还没有的Android版本的许可?

I would like that only users on the latest version of Android have to give these permission, and users on older Android versions don't have to.我希望只有使用最新版 Android 的用户才能授予这些权限,使用旧版 Android 的用户不必授予这些权限。

Is it possible to make this distinction in the manifest?是否可以在清单中进行这种区分?

I've seen a reference to Is it available to set checkSelfPermission on minimum SDK < 23?我已经看到参考是否可以在最小 SDK < 23 上设置 checkSelfPermission? but that question doesn't talk about the manifest xml and that's what my question is about但这个问题没有谈论清单 xml,这就是我的问题

User won't have to go explicit to the app-settings, just check the Android version with用户不必明确应用程序设置,只需检查 Android 版本

android.os.Build.VERSION.SDK_INT >= N

And if it is true, you should ask the permission with如果是真的,你应该征得许可

Activity.requestPermissions(String[] permissions, int requestCode)

Then listen the result with Activity.onPermissionsResult.然后使用 Activity.onPermissionsResult 收听结果。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM