java中url==null没反应,java – 解析URL的意图有时为null,抛出NullPointerException

我有一个

Android应用程序,它执行此操作:

PackageManager pm = getApplicationContext().getPackageManager();

Intent browserIntent = new Intent();

browserIntent.setAction(Intent.ACTION_VIEW);

browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);

browserIntent.setData(Uri.parse("http://www.google.com"));

ResolveInfo resolveInfo = pm.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY);

try {

String browserType = nutent.activityInfo.packageName;

} catch (NullPointerException npe) {

npe.printStackTrace();

}

我已经在4种不同的手机和许多不同的仿真器配置上进行了测试.所有这些都很好.但我正在从野外部署的应用程序中获取崩溃报告,因为resolveInfo有时为null.

立即修复是在崩溃我的应用程序之前捕获NPE并处理它(如上所述).但是我已经尝试了几天自己重现这一点而不能.在安装了单个默认浏览器的模拟器上,它解析为com.android.browser.BrowserActivity:

ResolveInfo{411ef228 com.android.browser.BrowserActivity p=0 o=0 m=0x2

Returns a ResolveInfo containing the final activity intent that was determined to be the best action. Returns null if no matching activity was found. If multiple matching activities are found and there is no default set, returns a ResolveInfo containing something else, such as the activity resolver.}

同样,在安装了多个浏览器的手机上,这有点不同……对于com.android.internal.app.ResolverActivity:

ResolveInfo{415c13b8 com.android.internal.app.ResolverActivity p=0 o=0 m=0x0}

resolveActivity()docs here状态:

Returns a ResolveInfo containing the final activity intent that was determined to be the best action. Returns null if no matching activity was found. If multiple matching activities are found and there is no default set, returns a ResolveInfo containing something else, such as the activity resolver.

所以我已经介绍了第一个场景,即被确定为最佳动作的活动意图.最后一个场景,即没有默认操作的多个匹配活动,返回ResolverActivity.

我真的想重现resolveActivity()的场景,在请求URL的活动时给我一个null.有没有人知道如何在没有设备生根的情况下完成这项工作?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值