- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我不知道如何检测用户是否取消了 Android 上的权限请求对话框。
有谁知道我需要调用什么函数来检查这个?
最佳答案
首先要做的是:这个问题有点老了,这个答案假定您使用的是更新的版本(我目前使用的是 3.7)。使用 3.0 版本的 SDK 可能可以做到这一点,但您应该尝试将您在项目中使用的 Facebook SDK 更新为更新版本,因为它们自 3.0 以来添加了很多功能和修复。
我正在使用 Session.StatusCallback
来监听 Session
生命周期更改,我将其注册到 UiLifecycleHelper
以提供更新我的 Activity 。
UiLifecycleHelper
将在用户完成与权限对话框的交互时触发更新,调用您的 Session.StatusCallback.call(Session, SessionState, Exception)
方法您的 Session.StatusCallback
实例已注册。为了检测用户取消权限请求,您可以处理传递给此方法的Exception
。
在我的代码中,我在发帖时是这样做的,但是读取权限请求应该是类似的:
@Override
public void call(Session session, SessionState state,Exception exception)
{
if(exception != null)
{
if(exception instanceof FacebookOperationCanceledException)
{
//make sure we don't continue posting
posting = false;
//the user cancelled it, no need to show a message or do anything
return;
}
else if(exception instanceof FacebookAuthorizationException)
{
Toast.makeText(FacebookActivity.this, "Failed to obtain Facebook permission to post on your behalf", Toast.LENGTH_LONG).show();
//don't continue posting, let the user retry it if he/she wants to
posting = false;
return;
}
}
//continue with checking that all permissions have been granted and post the action
}
我在 this question 的答案中找到了信息,但我处理 FacebookAuthorizationException
的方式不同。
此外,如果您在发布或使用其他扩展权限时恢复 Session
,我发现检查 SDK 给出的结果很有用,因为用户可能已经从其他地方取消了权限,例如 Facebook 网站。当后者发生时,您在应用程序中的 Session
对象将表明它仍然拥有该权限(例如 publish_actions
),而实际上它不再具有该权限.当 Session
对象被缓存并且其中的数据不新鲜时,就会发生这种情况。
这就是我正在做的检查权限是否丢失(即它已从其他地方而不是从应用程序中删除):
//note:
//I'm returning null further down the line because
//this code is run in an AsyncTask<Void,Void,Void>
Request request = new Request(
session,
graphPath,
params,
HttpMethod.POST);
Response response = request.executeAndWait();
GraphObject responseObject = response.getGraphObject();
if(responseObject == null)
{
FacebookRequestError fbre = response.getError();
if((fbre!=null) && (fbre.getCategory() == Category.PERMISSION))
{
requestFacebookPermissions(session);
return null;
}
else
{
postFailed();
return null;
}
}
关于android - Facebook 3.0 : How to detect user cancel the permission dialog on android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15487530/
我从 ssh 收到以下错误: Permissions 0777 for '/Users/username/.ssh/id_rsa' are too open. It is recommended th
我正在使用 WSL1(Windows Linux 子系统)和 Ubuntu 20.04.1 LTS 开发 Win10。我有一个 Samba (1.0) 网络共享,我想通过我的 Ubuntu 终端在上面
文件权限 我有一个文件 data.tgz我想解压缩。 -rw-r--r-- 1 username group 20342951248 mai 18 11:50 data.tgz 目录权限 文件所在的目
我正在尝试设置一些其他组不应该看到的组维护文件夹。目前,我通过取消单击@@sharing 选项卡中的“从更高级别继承权限”复选框来实现这一点,但我想自动执行此操作。 我在文档或谷歌搜索中找不到任何关于
在 Android 4 下,以下简单的 native C 代码行失败并出现 Permission denied 错误 when not run as 根: online_socket = socket
(我是 tortoise SVN 的新手) 我的乌龟 SVN 中有 2 个文件夹。每个人都需要一组不同的授权(我不想有权访问第一个文件夹的人对第二个文件夹具有读/写访问权限。 我怎样才能完成它?我注意
我用 tar -zxvf tarFile.tar.gz解压tarFile,但有错误提示tar: subfile :Cannot open: Permission denied . 我是root用户,权
我是 WAMP 的新手我今天刚刚安装了它。 设置进行得很顺利,本地主机似乎可以工作,但是当我尝试访问 phpMyAdmin 时我收到此错误: Forbidden You don't have perm
我想做的是从文件夹内的文件夹中获取 .mp3 文件。多次。 一切都很完美,除了当我尝试将文件复制到新文件夹(已经存在)时,它给出:[Errno 13]权限被拒绝: import os, shutil
我是 WAMP 的新手我今天刚刚安装了它。 设置进行得很顺利,本地主机似乎可以工作,但是当我尝试访问 phpMyAdmin 时我收到此错误: Forbidden You don't have perm
我正在开发一个应用程序,我在其中使用塔位置跟踪位置。所以我使用地理定位 api 来跟踪位置并访问手机状态以获取网络详细信息。 这很好用,突然间它开始给出 LOCATION_HARDWARE 权限的安全
这两种语法有什么区别。android:uses-permission 和 uses-permission。例如: 当我创建一个从存储中读取的 Activity 时,Android Studio 自
我正在尝试使用新的 GrantPermissionRule这是最新支持库的一部分。 在我的 list 中,我声明如下: 在我的代码中,我调用: @Rule public GrantPermissio
有没有navigator.permissions.query 的替代方案 Permissions API 查询以检查 geolocation 权限。导致它仍处于工作草案中并且浏览器兼容性较差。 W3C
这个错误真的真的很奇怪,我不知道如何重现它以及如何修复它,因为我进行了大量搜索,但没有任何用处。 这是堆栈跟踪: Stack Trace _______________________________
我正在尝试在 ubuntu 16.4 上安装 MaryTTS。 但是当我上线时 sudo -u mary git clone https://github.com/marytts/marytts.gi
在我们基于 Symfony2 的应用程序中,我们希望创建一个列表,列出系统中哪些用户对给定域对象具有权限。我们正在使用 ACL,我们的直接直觉是查看从相关域对象的 ACLProvider 返回的 AC
我今天收到这封邮件,但我没有使用 Admob 广告,而是使用 applovin 和 Facebook,我必须添加此权限还是仅适用于他们使用 Admob 的开发者? 即使没有像我一样的admob,每个人
我有一个 Jenkins 用户,我想授予其对 Jenkins 实例运行远程 CLI 的权限。第一个命令是获取 config.xml: java -jar jenkins-cli.jar -s http
我今天收到这封邮件,但我没有使用 Admob 广告,而是使用 applovin 和 Facebook,我必须添加此权限还是仅适用于他们使用 Admob 的开发者? 即使没有像我一样的admob,每个人
我是一名优秀的程序员,十分优秀!