简体   繁体   English

Android SDK 23+服务中的权限

[英]Android SDK 23+ Permissions in Services

I would like to update my project to SDK 23, but I have different services running in the background to receive data, store them, send etc... 我想将我的项目更新为SDK 23,但是我在后台运行着不同的服务来接收数据,存储数据,发送数据等。

So if I update the project I also have to change the permission requesting. 因此,如果我更新项目,则还必须更改权限请求。 Now I am wondering where the best place to do this is. 现在我想知道这样做的最佳位置在哪里。

Just at the moment received data should be saved? 就在此刻应该保存数据吗? But this would be pretty abstract for the user, especially if a config file or something needs to be transfered and the user gains nothing noticable from this. 但这对用户来说是非常抽象的,尤其是在需要传输配置文件或其他内容而用户从中获益不多的情况下。

Before starting the service just request all permissions the service requires? 在启动服务之前,只需请求服务需要的所有权限? This makes the whole concept absurd because it would be the same as so far... 这使整个概念变得荒谬,因为到目前为止它是相同的。

So thank you for your input! 因此,谢谢您的投入!

If I got the concept right, permissions should not be requested before they are really used. 如果我理解正确,则在真正使用权限之前,不应请求权限。

Correct, bearing in mind that the request is part of your user experience and therefore needs to be tied to the UI. 正确,请记住该请求是用户体验的一部分,因此需要与UI绑定。 Besides, from a technical standpoint, you can only request a permission from an Activity . 此外,从技术角度来看,您只能向Activity请求许可。

My general rule of thumb is: postpone requesting the permission until the user takes some positive step that will lead down a code path that requires that permission. 我的一般经验法则是:推迟请求权限,直到用户采取一些积极的措施,这将导致需要该权限的代码路径失败。

In some apps, that "positive step" is simply launching the app, as the permissions are needed right away. 在某些应用程序中,“积极步骤”只是启动应用程序,因为需要立即获得权限。 In that case, you check for the permissions in onCreate() of your launcher activity. 在这种情况下,您需要检查启动器活动的onCreate()中的权限。

In other apps, that "positive step" might be the user clicking on an action bar item, or on a nav drawer item, or on a button, or on a RecyclerView item, etc. In that case, you can delay asking for the permission until the user clicks that thing, so users who never click it will never have to be asked for the permission. 在其他应用中,该“正向步骤”可能是用户单击操作栏项,导航抽屉项,按钮或RecyclerView项等。在这种情况下,您可以延迟请求权限,直到用户单击该事物为止,因此永远不会要求从未单击它的用户获得该权限。

So, look at when and how your service is started. 因此,请查看何时以及如何启动服务。 That will determine what the user's "positive step" is that should be tied into your requesting the needed permissions. 这将确定用户的“肯定步骤”应该与您请求所需权限的联系在一起。

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

相关问题 是否可以在Android SDK 23+上使用RenderScript - Is it possible to use RenderScript on Android SDK 23+ Android M(API 23+)运行时存储权限 - Android M (API 23+) runtime storage permissions 除非我在android SDK 23+上手动将其关闭和打开,否则READ_CONTACTS权限无法正常工作 - READ_CONTACTS permission is not working unless i manually turn it off & on on android SDK 23+ 在Android 6.0(SDK 23)中检查自定义权限 - Checking custom permissions in Android 6.0 (sdk 23) Android 6目标sdk = 23安装权限 - Android 6 target sdk=23 permissions on install Android Send SMS Permission可在其他23+设备上使用,但不适用于OnePlus 5 - Android Send SMS Permission working on other 23+ devices but not with the OnePlus 5 应用程序被杀死时的后台操作? (Android API 23+) - Background operations when app is killed? (Android API 23+) 使用 Android 23+ 确定清单中是否存在权限 - Determine whether a permission is present in the manifest with Android 23+ 如何以编程方式获取Android设备的方向,api 23+ - How to get Android Device's orientation programatically, api 23+ Android 23+ - 从备份中排除 GCM 注册 ID - Android 23+ - Exclude GCM Registration ID from backup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM