- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 EasyPermissions 检查我的 android 是否已授予某些权限,如果没有则请求它们。很酷的库,效果很好,但我仍然没有弄清楚如果某些权限被拒绝如何处理。
所以基本上你在创建时运行这样的代码来检查
if (EasyPermissions.hasPermissions(Splash.this, perms )) {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String IMEI = telephonyManager.getDeviceId();
String SimSimSerial = telephonyManager.getSimSerialNumber();
Toast.makeText(Splash.this, "IMEI: " + IMEI + " SimSerial: " + SimSimSerial, Toast.LENGTH_SHORT).show();
} else {
EasyPermissions.requestPermissions(Splash.this, "Without these permissions, the app is unable to successfully complete authentication. Please allow us to access your device so that we can better serve you. " ,PERMS_REQUEST_CODE, perms );
}
代码分解:如果存在权限,则继续,否则请求就可以了。我的问题是,如果在请求期间有人点击永不询问按钮怎么办。 EasyPermissions 的人有一个功能
EasyPermissions.somePermissionPermanentlyDenied(Splash.this, permsList)
我的难题是在哪里调用此函数,因为请求权限方法不返回任何内容(无效)。我试过类似的东西
if (EasyPermissions.hasPermissions(Splash.this, perms )) {...
} else if (EasyPermissions.somePermissionPermanentlyDenied(Splash.this, permsList)) {
} else {
EasyPermissions.requestPermissions(Splash.this, "Without these permissions, the app is unable to successfully complete authentication. Please allow us to access your device so that we can better serve you. " ,PERMS_REQUEST_CODE, perms );
}
但它总是在启动时运行被拒绝的权限,而不是当用户在运行时实际单击从不按钮时。任何帮助表示感谢谢谢..
EasyPermissions 链接 https://github.com/googlesamples/easypermissions
最佳答案
如果您不想使用 Easy Permissions,请完整解释每种权限情况
/**
* Case 1: User doesn't have permission
* Case 2: User has permission
*
* Case 3: User has never seen the permission Dialog
* Case 4: User has denied permission once but he din't clicked on "Never Show again" check box
* Case 5: User denied the permission and also clicked on the "Never Show again" check box.
* Case 6: User has allowed the permission
*
*/
public void handlePermission() {
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// This is Case 1. Now we need to check further if permission was shown before or not
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// This is Case 4.
} else {
// This is Case 3. Request for permission here
}
} else {
// This is Case 2. You have permission now you can do anything related to it
}
}
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// This is Case 2 (Permission is now granted)
} else {
// This is Case 1 again as Permission is not granted by user
//Now further we check if used denied permanently or not
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// case 4 User has denied permission but not permanently
} else {
// case 5. Permission denied permanently.
// You can open Permission setting's page from here now.
}
}
}
关于java - 如何处理被拒绝的权限 Android M (EasyPermissions),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40161547/
我只想允许一个国家/地区访问,但排除该国家/地区内的代理。 这就是我所拥有的(为了方便起见,缩短了版本) order deny,allow deny from all allow from 139.
这个问题在这里已经有了答案: What is an unhandled promise rejection? (9 个回答) 关闭 4 年前。 我目前正在尝试实现我自己的 Promise,以便在 A
我在使用 Gitolite 推送 git 时遇到问题。 当我尝试这个时: git push origin :refs/tags/deployment 我收到这个错误: remote: D NAME/i
我已经为我的 laravel 5.0-dev 项目配置了 mysql,如下所示: 'mysql' => [ 'driver' => 'mysql', 'host' =>
我对 Web 和 SOF 进行了一些研究,但发现对于该错误没有任何真正的帮助。 我使用 Windows 10 Ubuntu Bash 安装了 Node 和 Puppeteer,但未能使其工作,但我设法
在我的应用审核期间,我收到了以下信息: “17.2:要求用户共享个人信息(例如电子邮件地址和生日)才能正常运行的应用将被拒绝 具体来说,您的应用仅使用Facebook登录名进行身份验证,但不包括该网站
我正在开发 VeriFone VX 终端的接口(interface)。虽然,这确实是一个普遍的 EMV 问题。我们的处理器的下限为零,因此它将始终在线发送。但是,如果它发生变化,您如何知道(哪些标签)
我编写了一些宏代码,根据表单提交向经理发送电子邮件(用于费用/审批流程),这是我使用谷歌表单/电子表格的第一个项目,所以也许我可能会错过一些简单的东西,但我为此浏览了 2 个教程,我的代码与重要的部分
clang 3.4 接受以下代码;而 vc++ NOV 2013 CTP 拒绝它并出现错误: error C2668: 'AreEqual' : ambiguous call to overloade
使用 nginx,您可以允许和拒绝范围和 ips (https://www.nginx.com/resources/admin-guide/restricting-access/)。使用realip模
官方编辑: 非常感谢您的帮助,但我仍然遇到问题。 我的 ffserver.conf 文件是这样的: # Port on which the server is listening. You must
我有一个问题:我是 Ubuntu 系统的根。我想授予用户(比如用户名是 X)执行任何命令的权限,但同时我有一个文件夹,除了我的用户(当然不是 X,因为它是 Admin ) 或根。有什么建议么?谢谢!
我使用 Apache2.2 作为 tomcat 服务器的前端。我想限制对某个位置的访问,但允许对子位置的所有访问,但遇到了一些麻烦。 我目前拥有的是: AllowOverride None
就像 this person ,我一直在为浏览器缓存 SSL session 而苦苦挣扎。简而言之,如果选择了客户端证书,则无法以编程方式清除状态,除非在 IE 中使用 document.execCo
我的网站是在由 Apache 服务器提供服务的 Angular 上设置的。我通过 View 将内容动态加载到主页上。 现在以下是我的问题: 我建立这个网站的主要目的是通过 google adsense
我最近遇到了我的应用程序的问题,当它突然被 Google Play 拒绝时因为他们发现我使用的是背景位置 .但实际上我并没有使用这个功能。我只有 ACCESS_COARSE_LOCATION和 ACC
function sendPushNotification(subscription, urlEncodedData){ try { webpush.sendNotification(su
我包裹了一个 request-promise-native调用返回 promise 的函数。 import request from 'request-promise-native'; functio
我正在开发我的 meteor 项目,并开始设置我的第一个更复杂的允许/拒绝规则。我发现很难看出哪些允许触发,哪些不允许触发,以及这些函数中的某些变量包含什么。例如: List.allow({ u
我正在 AngularJS 中创建一个 Factory,它是这样的: if (href) { return $http({ method: method, url: item.href });
我是一名优秀的程序员,十分优秀!