如何从ResolveInfo启动Intent [英] How to start an Intent from a ResolveInfo

查看:421
本文介绍了如何从ResolveInfo启动Intent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为android创建自定义启动器,并且正在尝试找出如何启动与我不同的应用程序.我认为实现目的的方法是意图,并且我在这里找到了一篇文章:

从您自己的(意图)打开另一个应用程序

我不太明白答案!有人可以给我一个简短的代码段或一系列步骤,从单个ResolveInfo到启动由该ResolveInfo表示的应用程序吗?

解决方案

给出一个名为launchableResolveInfo:

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);

(来自 https://github.com/commonsguy/cw-omnibus/tree/master/Introspection/Launchalot )

I'm trying to make a custom launcher for android, and I'm trying to figure out how to launch a different application form mine. I figured the way to do it was intents, and I've found a post on it here:

Open another application from your own (intent)

I don't really understand the answer though! Can someone give me a concise snippet or series of steps to go from a single ResolveInfo to launching the app represented by that ResolveInfo?

解决方案

Given a ResolveInfo named launchable:

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);

(from https://github.com/commonsguy/cw-omnibus/tree/master/Introspection/Launchalot)

这篇关于如何从ResolveInfo启动Intent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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