在Android中添加Layer库依赖项会抑制requestPermissions对话框 [英] Adding the Layer library dependency in Android suppresses requestPermissions dialog

查看:79
本文介绍了在Android中添加Layer库依赖项会抑制requestPermissions对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个非常非常小的演示应用程序,在运行Android 6.0.1版的Nexus 5上重现了该错误.该应用程序位于github上的此处: https://github.com/lexi-sr/LayerPermission

我最近添加了2个提交,它们针对API 23并在运行时请求权限,但是仍然无法正常工作.

在这2次提交中,它具有以下设置:

  • 目标SDK:23
  • 编译层0.20.3

1)在提交删除层依赖性允许弹出对话框请求权限…"的情况下,它不具有层依赖性: 方法ActivityCompat.requestPermissions打开一个对话框,请求联系人"权限,并且onRequestPermissionsResult方法中的log语句记录已授予该权限.

2)在提交请求权限不起作用"的情况下,它确实具有图层依赖性: ActivityCompat.requestPermissions不会打开任何对话框,但是onRequestPermissionsResult中的一条log语句仍会打印,记录它没有权限.

似乎添加层依赖性正在抑制运行时请求权限的能力.为什么会这样?

解决方案

幸运的是,层支持团队可以帮助我解决这一问题.它在演示应用程序(针对SDK 23)中解决了我的问题,而在我的真实应用程序(针对SDK 22,以避免在运行时请求权限)中解决了我的问题.将tools:node="replace"放入GET_ACCOUNTS的使用许可行后,弹出对话框便会出现,并在演示应用程序中授予了权限,而在以SDK 22为目标的真实应用程序中,权限不再丢失. >

这是Layer支持团队的详细说明:

图层SDK使用以下命令请求GET_ACCOUNTS权限 maxSdkVersion为18. 合并后,这将覆盖清单中的权限请求, 因此不要求19岁以上的权限.你可以尝试追加 tools:node ="replace"授予您应用清单中的权限?这 该行应显示为:

<uses-permission android:name="android.permission.GET_ACCOUNTS" tools:node="replace" />

有关maxSdkVersion文档,请参见此处: http://developer.android.com/guide/topics/manifest /uses-permission-element.html

有关工具:节点文档,请参见此处: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-tools:node-markers

彼得

I made a very, very small demo app reproducing the bug on a Nexus 5 running Android version 6.0.1. The app is on github here: https://github.com/lexi-sr/LayerPermission

I recently added 2 commits in which it targets API 23 and requests permissions at run time, but it still didn't work.

In these 2 commits, it has these settings:

  • Target SDK: 23
  • compiles Layer 0.20.3

1) In the commit "Removing layer dependency allows the popup dialog to request the perm…", where it does NOT have layer dependency: The method ActivityCompat.requestPermissions opens a dialog that requests the Contacts permission, and a log statement within the onRequestPermissionsResult method logs that the permission has been granted.

2) In the commit "Requesting permissions does not work" where it DOES have layer dependency: ActivityCompat.requestPermissions does not open up any dialogs, but a log statement within onRequestPermissionsResult still prints, logging that it does not have the permission.

It seems like adding the layer dependency is suppressing the ability to request for permissions at run time. Why is this happening?

解决方案

Luckily, the layer support team was able to help me with this. It solved my problem in the demo app (which targeted SDK 23) and my real app (which targeted SDK 22, to avoid requesting permissions at runtime). After I put tools:node="replace" into my uses-permission line for GET_ACCOUNTS, the pop up dialog was able to appear and grant the permission in the demo app, and the permission was no longer missing in the real app which targeted SDK 22.

Here is the detailed explanation from the Layer support team:

The layer SDK requests the GET_ACCOUNTS permission using a maxSdkVersion of 18. It would appear that when the manifests get merged this is overwriting the permission request in your manifest, thus not requesting that permission for 19+. Could you try appending tools:node="replace" to the permission in your app's manifest? The line should read as:

<uses-permission android:name="android.permission.GET_ACCOUNTS" tools:node="replace" />

See here for the maxSdkVersion documentation: http://developer.android.com/guide/topics/manifest/uses-permission-element.html

See here for the tools:node documentation: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-tools:node-markers

Peter

这篇关于在Android中添加Layer库依赖项会抑制requestPermissions对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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