Android fetch 局域网,已安装Android Fetch并在设备中安装默认浏览器

我可以在Intent.CATEGORY_LAUNCHER的帮助下获得Launcher中的所有应用程序.

所以为了测试我创建了一个测试活动,这个活动包含一个按钮,如果按下按钮,它应该显示设备中的应用程序

NOTE: `it should not display specific. for example i needed only Browser it should display all browser applications.`

我用这种方式尝试了一个小代码:

btn.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

Intent intent = new Intent(Intent.ACTION_MAIN);

intent.addCategory(Intent.CATEGORY_APP_BROWSER);

List mainLauncherList = getPackageManager().queryIntentActivities(intent, 0);

System.out.println("the list iss = " +mainLauncherList);

}

});

该列表仅返回一个浏览器,即单个浏览器.

解决方法:

而不是类别,给意图一个动作,并查询可以ACTION_VIEW的URL,如下所示:

Intent intent = new Intent(Intent.ACTION_VIEW);

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

List mainLauncherList = getPackageManager().queryIntentActivities(intent, 0);

Log.e("Browsers","the list iss = " +mainLauncherList);

返回的内容如下:

[ResolveInfo{44e9d350 com.android.browser.BrowserActivity p=0 o=0 m=0x208000}]

假设您安装了多个浏览器,它将包含所有浏览器.也许我误解了你的问题,但是如果你尝试启动打开url的意图,这在技术上会返回相同的应用程序.

至于获取这些应用程序的启动器活动,因为你已经知道如何获得所有主要的应用程序和我给你的代码,你可以匹配包名称(可以)找到启动器( ?)

UPDATE

ArrayList allLaunchers = new ArrayList();

Intent allApps = new Intent(Intent.ACTION_MAIN);

List allAppList = getPackageManager().queryIntentActivities(allApps, 0);

for(int i =0;i

Intent myApps = new Intent(Intent.ACTION_VIEW);

myApps.setData(Uri.parse("http://www.google.es"));

List myAppList = getPackageManager().queryIntentActivities(myApps, 0);

for(int i =0;i

if(allLaunchers.contains(myAppList.get(i).activityInfo.packageName)){

Log.e("match",myAppList.get(i).activityInfo.packageName+"");

}

}

正如我所说,你从启动器获得所有包,并将它们与能够执行操作的包,拍摄照片或浏览网页进行匹配.你应该能够用这个去做.

标签:android,android-intent,launcher

来源: https://codeday.me/bug/20190530/1183337.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值