从意图打开第三方应用程序

编程入门 行业动态 更新时间:2024-10-24 22:30:53
本文介绍了从意图打开第三方应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在一个应用程序的工作是我要打开其他应用程序。唯一的问题是,我不知道如何引用第三方应用程序。我刨使用意图。你可以参考一下吧期运用只有软件包名,或者你所需要的主要活动的意图。有没有找到合适的意图任何简单的方法,然后引用它。

解决方案   

我在一个应用程序中的工作,我要打开其他应用程序。

我是间preting这是这意味着你正在创建一个发射器,类似于在主屏幕上发现的。

  

你能参考一下吧期运用只有软件包名,还是你所需要的主要活动的意图。

发射器使用 ACTION_MAIN / CATEGORY_LAUNCHER 意图。

  

有没有找到合适的意图任何简单的方法,然后引用它。

使用软件包管理系统来找出所有可能的 ACTION_MAIN / CATEGORY_LAUNCHER 活动,然后显示这些给用户以供选择。然后,您可以构建一个合适的意图启动他们的具体选择。

这是一个实现了发射器示例项目。

要拿出的东西,就可以推出名单,该样本应用程序使用:

软件包管理系统PM = getPackageManager();主要意图=新意图(Intent.ACTION_MAIN,NULL);main.addCategory(Intent.CATEGORY_LAUNCHER);清单< ResolveInfo> launchables = pm.queryIntentActivities(主,0);

这是实际的启动逻辑,在基于用户点击这些launchables之一的 ListActivity :

@覆盖  保护无效onListItemClick(ListView中升,视图V,                                 INT位置,长的id){    ResolveInfo可启动= adapter.getItem(位置);    ActivityInfo活性= launchable.activityInfo;    组件名NAME =新的组件名(activity.applicationInfo.packageName,                                         activity.name);    意图I =新意图(Intent.ACTION_MAIN);    i.addCategory(Intent.CATEGORY_LAUNCHER);    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |                Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);    i.setComponent(名);    startActivity(ⅰ);  }

I am working on an app were I am going to open other apps. The only problem is that I do not know how to refer to third party apps. I am planing to use an intent. Can you refer to it useing only the packagename, or do you need the Main Activity intent. Are there any simple ways of finding the right intent, and then refer to it.

解决方案

I am working on an app were I am going to open other apps.

I am interpreting this as meaning that you are creating a launcher, akin to the ones found on home screens.

Can you refer to it useing only the packagename, or do you need the Main Activity intent.

Launchers use an ACTION_MAIN/CATEGORY_LAUNCHER Intent.

Are there any simple ways of finding the right intent, and then refer to it.

Use PackageManager to find all the possible ACTION_MAIN/CATEGORY_LAUNCHER activities on the device, and then display those to the user to choose from. You can then construct a suitable Intent for starting up their specific choice.

Here is a sample project that implements a launcher.

To come up with the list of things that could be launched, that sample app uses:

PackageManager pm=getPackageManager(); Intent main=new Intent(Intent.ACTION_MAIN, null); main.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> launchables=pm.queryIntentActivities(main, 0);

And here is the actual launching logic, based upon the user clicking on one of those "launchables" in a ListActivity:

@Override protected void onListItemClick(ListView l, View v, int position, long id) { ResolveInfo launchable=adapter.getItem(position); ActivityInfo activity=launchable.activityInfo; ComponentName name=new ComponentName(activity.applicationInfo.packageName, activity.name); Intent i=new Intent(Intent.ACTION_MAIN); i.addCategory(Intent.CATEGORY_LAUNCHER); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); i.setComponent(name); startActivity(i); }

更多推荐

从意图打开第三方应用程序

本文发布于:2023-11-27 03:31:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636392.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第三方   意图   应用程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!