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

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

问题描述:

我知道如何更新我自己的程序,我知道如何使用预定义的 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:

  1. 使用 action=MAINcategory=LAUNCHER
  2. 创建意图
  3. 使用 context.getPackageManager
  4. 从当前上下文中获取 PackageManager
  5. packageManager.queryIntentActivity(, 0) 其中意图具有 category=LAUNCHERaction=MAINpackageManager.resolveActivity(, 0) 使用 main/launcher 获取第一个活动
  6. 获取您感兴趣的ActivityInfo
  7. ActivityInfo,获取packageNamename
  8. 最后,使用 category=LAUNCHERaction=MAINcomponentName = new ComponentName(packageName, name) 和 setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
  9. 最后,context.startActivity(newIntent)
  1. Create an intent with action=MAIN and category=LAUNCHER
  2. Get the PackageManager from the current context using context.getPackageManager
  3. packageManager.queryIntentActivity(<intent>, 0) where intent has category=LAUNCHER, action=MAIN or packageManager.resolveActivity(<intent>, 0) to get the first activity with main/launcher
  4. Get theActivityInfo you're interested in
  5. From the ActivityInfo, get the packageName and name
  6. Finally, create another intent with with category=LAUNCHER, action=MAIN, componentName = new ComponentName(packageName, name) and setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
  7. Finally, context.startActivity(newIntent)