How to start an Intent from a ResolveInfo

穿精又带淫゛_ 提交于 2019-12-20 09:34:46

问题


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?


回答1:


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)




回答2:


Create an new Intent by this way.

    Intent intent = new Intent();
    intent.setClassName(resolveInfo.activityInfo.applicationInfo.packageName,
            resolveInfo.activityInfo.name);
    startActivity(intent);


来源:https://stackoverflow.com/questions/12504954/how-to-start-an-intent-from-a-resolveinfo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!