背景:

微博sdk 登录提示

Application requires permission to access the Internet

如上图

问题分析:

这种情况,只有手机上没有安装微博客户端的时候,才会出现。
我们可以跟下微博sdk 的代码,在这里:

protected void startWebAuth() {if (!NetworkHelper.hasInternetPermission(this.mAuthActivity)) {UIUtils.showAlert(this.mAuthActivity, "Error", "Application requires permission to access the Internet");} else {AuthWebViewRequestParam param = new AuthWebViewRequestParam(authInfo, WebRequestType.AUTH, mAuthListenerKey, "微博登录", url, this.mAuthActivity);Intent intent = new Intent(this.mAuthActivity, WeiboSdkWebActivity.class);Bundle bundle = new Bundle();param.fillBundle(bundle);intent.putExtras(bundle);this.mAuthActivity.startActivity(intent);}}

很明显,NetworkHelper.hasInternetPermission返回了fasle,也就是没有权限才会有这个弹窗。
我们看下这个是怎么写的:

    public static boolean hasInternetPermission(Context context) {if (context != null) {return 0 == context.checkCallingPermission("android.permission.INTERNET");} else {return true;}}

这里调用了checkCallingPermission!如果是同一个进程调用这个方法,一定会返回-1,也就是permission define。(权限拒绝)

我们开始看源码:

   /*** Determine whether the calling process of an IPC you are handling has been* granted a particular permission.  This is basically the same as calling* {@link #checkPermission(String, int, int)} with the pid and uid returned* by {@link android.os.Binder#getCallingPid} and* {@link android.os.Binder#getCallingUid}.  One important difference* is that if you are not currently processing an IPC, this function* will always fail.  This is done to protect against accidentally* leaking permissions; you can use {@link #checkCallingOrSelfPermission}* to avoid this protection.** @param permission The name of the permission being checked.** @return {@link PackageManager#PERMISSION_GRANTED} if the calling* pid/uid is allowed that permission, or* {@link PackageManager#PERMISSION_DENIED} if it is not.** @see PackageManager#checkPermission(String, String)* @see #checkPermission* @see #checkCallingOrSelfPermission*/@CheckResult(suggest="#enforceCallingPermission(String,String)")@PackageManager.PermissionResultpublic abstract int checkCallingPermission(@NonNull String permission);/*** Determine whether <em>you</em> have been granted a particular permission.** @param permission The name of the permission being checked.** @return {@link PackageManager#PERMISSION_GRANTED} if you have the* permission, or {@link PackageManager#PERMISSION_DENIED} if not.** @see PackageManager#checkPermission(String, String)* @see #checkCallingPermission(String)*/@PackageManager.PermissionResultpublic abstract int checkSelfPermission(@NonNull String permission);

我们看下checkCallingPermission 的实现,以及checkSelfPermission 的实现:

    @Overridepublic int checkCallingPermission(String permission) {if (permission == null) {throw new IllegalArgumentException("permission is null");}int pid = Binder.getCallingPid();if (pid != Process.myPid()) {return checkPermission(permission, pid, Binder.getCallingUid());}return PackageManager.PERMISSION_DENIED;}
checkCallingPermission 如果是同一个进程的话,那么直接返回PERMISSION_DENIED 。只适用于不同进程之间判断有没有权限。
    @Overridepublic int checkSelfPermission(String permission) {if (permission == null) {throw new IllegalArgumentException("permission is null");}return checkPermission(permission, Process.myPid(), Process.myUid());}这个才是判断当前进程,当前用户,有没有这个权限。

解决方法:

我们重写调用微博登录的activity 的 checkCallingPermission 方法:

    @Overridepublic int checkCallingPermission(String permission) {return super.checkCallingOrSelfPermission(permission);}

这样的话,checkCallingOrSelfPermission 就会返回正确的,当前应用有没有网络权限。就不会再弹窗了。

解决微博登录 Application requires permission to access the Internet相关推荐

  1. Centos7 系统更改apache默认网站目录(解决You don't have permission to access / on this server问题)...

    当我们在Centos7中配置好Apache时,发现apache默认解析目录是在 /var/www/html,也就是说当访问服务器 IP 或者本地 localhost 时, 默认定位到这个目录里的 in ...

  2. phpStudy配置站点 解决You don't have permission to access / on this server

    1.配置站点:打开phpStudy->其他选项菜单->站点域名管理 2.配置站点:打开phpStudy->其他选项菜单->打开hosts 3.在apache的配置文件vhost ...

  3. 403 Forbidden You don‘t have permission to access this resource. Apache Server at IP Port 80的解决方法

    ECS下载站Forbidden You don't have permission to access this resource. Apache Server at IP Port 80的解决方法 ...

  4. java.lang.SecurityException: Injecting to another application requires INJECT_EV ENTS permission

    现在的我是对自己着实佩服,,手机连接电脑时,因打开[允许通过USB调试修改权限或模拟点击]需要15s,一次是5s共3次,我就放弃了,然后我觉得需要的时候我会想到打开的,万万没想到还是忘了打开,然后为了 ...

  5. 输入http://localhost/,apache出现You don't have permission to access/on this server.的提示,如何解决?...

    本地搭建wamp,输入http://127.0.0.1访问正常,当输入http://localhost/,apache出现You don't have permission to access/on ...

  6. 提示YOU DON'T HAVE PERMISSION TO ACCESS / ON THIS的解决方法

    Forbidden  You don't have permission to access / on this server.   解决办法 打开 httpd.conf 文件, 将 #  onlin ...

  7. apache 提示You don't have permission to access /test.php on this server.怎样解决

    关键字: Apache   403  Forbidden 系统配置: 操作系统:Red Hat Linux 6.2 Web服务器:Apache 3.1.1+jakarta-tomcat 3.1.1 数 ...

  8. Forbidden You don't have permission to access / on this server.解决方法

    wamap本地搭建完毕后,输入http://localhost/出现下面的问题 问题报错:Forbidden You don't have permission to access / on this ...

  9. (已解决)wamp + Apache报错:出现403Forbidden You don't have permission to access / on this server.

    文章目录 `解决办法:` `*** `附件 · 延伸阅读 · 参考: 解决办法: 注意: 案例环境:win7 x64 或 win10 仅仅只需要修改apache配置文件httpd.conf 即可. 上 ...

最新文章

  1. 阻止 WSL 自动生成/etc/hosts 文件
  2. easyui打开新的选项卡_Easyui Tabs 标签页/选项卡_EasyUI 插件
  3. JavaFX 2:创建登录表单
  4. Java工作笔记-Map的基本用法
  5. Ubuntu下安装setuptools
  6. terminal中常用的rvm指令
  7. 【转载】大型网站性能
  8. 4一20ma电流有源与无源区别_一文读懂有源信号、无源信号、干接点、湿接点
  9. python远程调用摄像头_Python调用摄像头
  10. php微信公众号报修系统,微信公众号如何实现在线报修系统?
  11. 基于Linux下的即时通讯聊天室项目(全代码 有注释 可直接运行)
  12. css实现图片毛玻璃效果
  13. vue加载图片出现404用默认图片替换的方法
  14. 解决pip install (包名)报错问题
  15. SpringMVC(8)——格式化转换器Formatter
  16. 百万点赞怎么来?用Python制作抖音视频原来这么简单!
  17. 美国bluehost虚拟主机怎么样?bluehost主机详细评测!
  18. Day463.视图存储过程存储函数 -mysql
  19. Gin框架学习(三)
  20. Python中的shape[0]、shape[1]和shape[-1]含义

热门文章

  1. Java实现均摊_Java均摊复杂度和防止复杂度的震荡原理分析
  2. MATLAB中如何将一幅图像的地理信息写入另一幅图像
  3. ads无法启用状态服务器,NAC ADSSO 无法工作在Microsoft 2008服务器版本
  4. Kubernetes(1) kubectl 入门
  5. Linux 批量依赖库拷贝(ldd)
  6. 深入struts2.0(七)--ActionInvocation接口以及3DefaultActionInvocation类
  7. 《数据分析实战 基于EXCEL和SPSS系列工具的实践》一第2章 数据分析的理论、工具、模型...
  8. Apache CXF实战之六 创建安全的Web Service
  9. ios-http协议
  10. Revit API导出GBXML