Android - 将 targetSdkVersion 设置为 22 以避免运行时权限,有哪些潜在问题? [英] Android - set targetSdkVersion to 22 to avoid runtime permissions, what are the potential problems?

查看:21
本文介绍了Android - 将 targetSdkVersion 设置为 22 以避免运行时权限,有哪些潜在问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以总结一下将 targetSdkVersion 设置为 22 以避免处理运行时权限的缺点吗?

Can somebody summarize the drawbacks to setting the targetSdkVersion to 22 to avoid handling runtime permissions?

在阅读 Google 文档和其他一些 Stack Overflow 帖子后,我发现唯一的缺点是用户可以在安装时授予权限,然后进入他们的操作系统设置并撤销该特定应用程序的特定权限,然后再次运行该应用程序.然而,从几个例子中我发现这在代码中处理起来并不困难.

After reading the Google docs on this and a few other Stack Overflow posts, the only downside I can find is that a user could grant permission at install time, then go into their OS settings and revoke that specific permission for that specific app, and then run the app again. However from a few of the examples I found this is not difficult at all to deal with in code.

这真的是在安装时使用 targetSdkVersion 22 强制权限的唯一缺点吗?未来数年,情况还会如此吗?

Is this really the only drawback to using targetSdkVersion 22 to force permissions at install time? Will things stay this way for years into the future?

此外,例如,如果我在 build.gradle 文件中使用这些设置:

Also, if for example I use these settings in my build.gradle file:

compileSdkVersion 24
buildToolsVersion "24.0.1"
minSdkVersion 19
targetSdkVersion 22

我还能访问 API 23 吗?应用中有 24 个功能,还是我仅限于 22 个及更早的功能?

Can I still access API 23 & 24 features in an app or am I limited to 22 and earlier?

在有人回复最佳做法是不要这样做并根据 Google 建议的需要在运行时请求权限"之前,是的,我当然知道这一点.是的,我也知道一些示例试图提供样板代码以请求运行时权限,例如:

Before somebody responds with "It is best practice to not do this and to request permissions at runtime as needed as recommended by Google", yes, of course I'm aware of this. And yes, I'm also aware of some examples out there that attempt to provide boiler plate code to for ask for runtime permissions such as:

https://github.com/googlesamples/easypermissions

但是,至少有两种情况我能想到在安装时请求权限而不是在未授予权限的情况下不安装应用程序是非常有利的:

However there are at least two situations I can think of where it would be very advantageous to request permissions at install time and not install the app if the permissions are not granted:

1) 假设我报告的人在工作周进行到一半时问:您能否为周五会议汇总一个概念验证 Android 应用程序,让 XYZ 向一些访客展示我们当天有哪些访客?"如果我必须将一个应用程序的快速 alpha 版本放在一起,而我只有几天的时间来完成,而将基本功能放在一起需要那么长时间,并且该应用程序将需要,比如说,4 个权限,它会最好在安装时要求 alpha 版本的所有权限,以便我有时间花在应用程序功能上.然后,如果我继续进行,当我将应用程序移至测试版然后移至最终版时,根据需要在运行时将权限请求一一更改.

1) Suppose half way through the work week the person I report to asks "Can you throw together a proof of concept Android app for the Friday meeting that does XYZ to show some visitors we are having that day?" If I have to throw together a quick alpha version of an app and I only have a few days to do it, and it will take that long to put together the basic functionality, and the app will require, say, 4 permissions, it would be much better to demand all permissions at install time for the alpha version so I have the time to spend on the app functionality. Then if I get the go ahead, as I move the app to beta and then to final, to change permission requests to one by one at run time as needed.

2) 某些应用程序绝对需要某些权限才能使用.例如,如果我正在编写一个 OpenCV 应用程序,它从相机中获取图像,然后根据图像中的内容或不包含的内容执行某些操作,那么最好不要让这样的应用程序开始安装,如果用户不愿意授予相机权限.

2) Some apps absolutely need certain permissions to be of any use. For example, if I'm writing an OpenCV app that takes images from the camera and then does something based on what is or is not in the images, it would be preferable to not let such an app be installed to begin with if the user is not willing to grant camera permission.

我真的希望 Google 将其保留为在安装时请求/要求权限的选项,并且还提供在运行时请求权限的选项.对于只能在运行时请求权限的决定,是否有任何负面的开发人员反馈?Google 是否有可能在未来版本中允许在安装时或运行时请求权限,在这种情况下,我可以在此期间简单地使用 targetSdkVersion 22 选项?

I really wish Google had left it in as an option to request/require permissions at install time, and also offer the option to request permissions at runtime. Has there been any negative developer feedback regarding the decision to be able to ask for permissions at runtime only? Is it possible that Google may allow permission requests at install time or run time in a future version, in which case I could simply use the targetSdkVersion 22 option in the interim?

推荐答案

这真的是在安装时使用 targetSdkVersion 22 强制权限的唯一缺点吗?

Is this really the only drawback to using targetSdkVersion 22 to force permissions at install time?

没有.例如,除非您的 targetSdkVersion 为 24 或更高版本,否则 Android 7.0+ 设备用户在尝试使用您的应用时会收到此应用可能不支持分屏"Toast在分屏模式下.

No. For example, unless your targetSdkVersion is 24 or higher, Android 7.0+ device users will get a "this app may not support split-screen" Toast when trying to use your app in split-screen mode.

此外,关于运行时权限,请记住,targetSdkVersion 为 22 或更低意味着用户将在安装时收到您请求的所有权限的提示.你似乎认为这是积极的.潜在用户可能不同意.如果在安装时请求各种权限的应用程序 A 和不请求各种权限的应用程序 B 之间进行选择,用户将倾向于选择应用程序 B,没有充分的理由选择应用程序 A.随着时间的推移,随着 Android 6.0+ 推出更多和更多用户,在安装时请求权限的应用将被视为未维护或编写不当,因为用户期望不必事先同意权限.

Also, with respect to runtime permissions, bear in mind that a targetSdkVersion of 22 or lower means that the user will be prompted for all your requested permissions at install time. You appear view this as a positive. Prospective users may disagree. Given a choice between App A which requests all sorts of permissions at install time and App B that does not, users will tend to choose App B, absent strong reasons to go with App A. Over time, as Android 6.0+ rolls out to more and more users, apps that request permissions at install time will be viewed as unmaintained or poorly written, as users will expect not to have to agree to permissions up front.

未来数年,事情还会如此吗?

Will things stay this way for years into the future?

没有

我还能访问 API 23 吗?应用中的 24 个功能

Can I still access API 23 & 24 features in an app

是的,尽管由于您的 targetSdkVersion,有些可能会有所不同.

Yes, though some may behave differently due to your targetSdkVersion.

Google 是否有可能在未来版本中允许安装时或运行时的权限请求

Is it possible that Google may allow permission requests at install time or run time in a future version

一切皆有可能.一般来说,Google 不会像这样讨论未来的计划.

Anything is possible. In general, Google does not discuss future plans like this.

这篇关于Android - 将 targetSdkVersion 设置为 22 以避免运行时权限,有哪些潜在问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆