最新消息:关注【已取消】微信公众号,可以获取全套资料,【全套Java基础27天】【JavaEE就业视频4个月】【Android就业视频4个月】

Call requires permission which may be rejected by user错误完美解决

Android 太平洋学习网 浏览 评论

我们在调用android拨打电话功能的时候,“startActivity(intent)”报了如下这样的错误:

Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException less... (Ctrl+F1) 

This check scans through your code and libraries and looks at the APIs being used, and checks this against the set of permissions required to access those APIs. If the code using those APIs is called at runtime, then the program will crash.  Furthermore, for permissions that are revocable (with targetSdkVersion 23), client code must also be prepared to handle the calls throwing an exception if the user rejects the request for permission at runtime.  Issue id: MissingPermission

checkPermission错误如图所示:

QQ截图20181027110221.jpg

错误分析:

从上述错误的英文可以看出,如果用户拒绝了直接拨号的权限,我们此时点击打电话,将会报错误,你该怎么处理?

其中有一个“SecurityException”的英文,它的意思就是告诉我们,如果对方没有在应用中授权“电话”权限,将会抛出SecurityException错误,所以我们知道了上面提示我们的原因之后,请看下方的解决方案!

解决方案:

使用try catch捕获抛出“SecurityException”异常即可,解决方案如下,此时startActivity就不会报错误了,如下:

QQ截图20181027111130.jpg

来源网站:太平洋学习网,转载请注明出处:http://www.tpyyes.com/a/android/785.html
"文章很值,打赏犒劳作者一下"
微信号: Javaweb_engineer

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

与本文相关的文章

发表我的评论
取消评论

表情

您的回复是我们的动力!

  • 昵称 (必填)

网友最新评论