从意图打开第三方应用程序 [英] Open third party app from intent

查看:104
本文介绍了从意图打开第三方应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


解决方案

  

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


我是间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);    
  }

这篇关于从意图打开第三方应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆