从您自己的(意图)打开另一个应用程序
我知道如何更新我自己的程序,我知道如何使用预定义的 Uri(例如短信或电子邮件)打开程序
I know how to update my own programs, and I know how to open programs using the a predefined Uri (for sms or email for example)
我需要知道如何创建 Intent 以打开 MyTracks 或任何其他我不知道他们听什么意图的应用程序.
I need to know how I can create an Intent to open MyTracks or any other application that I don't know what intents they listen to.
我从 DDMS 得到了这个信息,但我没有成功地将它转化为我可以使用的 Intent.这是在手动打开 MyTracks 时获取的.
I got this info from DDMS, but I havn't been succesful in turning this to an Intent I can use. This is taken from when opening MyTracks manually.
感谢您的帮助
05-06 11:22:24.945: INFO/ActivityManager(76): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.google.android.maps.mytracks/com.google.android.apps.mytracks.MyTracks bnds=[243,338][317,417] }
05-06 11:22:25.005: INFO/ActivityManager(76): Start proc com.google.android.maps.mytracks for activity com.google.android.maps.mytracks/com.google.android.apps.mytracks.MyTracks: pid=1176 uid=10063 gids={3003, 1015}
05-06 11:22:26.995: INFO/ActivityManager(76): Displayed activity com.google.android.maps.mytracks/com.google.android.apps.mytracks.MyTracks: 1996 ms (total 1996 ms)
首先,Android 中应用"的概念是一个稍微扩展的概念.
Firstly, the concept of "application" in Android is slightly an extended one.
一个应用程序 - 从技术上讲是一个进程 - 可以有多个活动、服务、内容提供者和/或广播侦听器.如果其中至少有一个正在运行,则应用程序已启动并正在运行(进程).
An application - technically a process - can have multiple activities, services, content providers and/or broadcast listeners. If at least one of them is running, the application is up and running (the process).
因此,您必须确定的是您希望如何启动应用程序".
So, what you have to identify is how do you want to "start the application".
好的……以下是您可以尝试的内容:
Ok... here's what you can try out:
- 使用
action=MAIN
和category=LAUNCHER
创建意图 - 使用
context.getPackageManager
从当前上下文中获取 -
packageManager.queryIntentActivity(
其中意图具有, 0) category=LAUNCHER
、action=MAIN
或packageManager.resolveActivity(
使用 main/launcher 获取第一个活动, 0) - 获取您感兴趣的
ActivityInfo
- 从
ActivityInfo
,获取packageName
和name
- 最后,使用
category=LAUNCHER
、action=MAIN
、componentName = new ComponentName(packageName, name)
和 setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - 最后,
context.startActivity(newIntent)
PackageManager
- Create an intent with
action=MAIN
andcategory=LAUNCHER
- Get the
PackageManager
from the current context usingcontext.getPackageManager
-
packageManager.queryIntentActivity(<intent>, 0)
where intent hascategory=LAUNCHER
,action=MAIN
orpackageManager.resolveActivity(<intent>, 0)
to get the first activity with main/launcher - Get the
ActivityInfo
you're interested in - From the
ActivityInfo
, get thepackageName
andname
- Finally, create another intent with with
category=LAUNCHER
,action=MAIN
,componentName = new ComponentName(packageName, name)
andsetFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- Finally,
context.startActivity(newIntent)