views:

47

answers:

1

Android provides a lot of Intents in the base OS and packages. How do I determine the arguments (that is, Data, Extras, etc.) to send to an Intent? For example, you can open the Settings app to show the Application Info for a particular app using this intent:

String pkgname = "com.example.application"; // whatever the app is

Intent it = new Intent(Intent.ACTION_VIEW);
it.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
it.putExtra("com.android.settings.ApplicationPkgName", pkgname);
it.putExtra("pkg", pkgname);

The problem is that I only know that those Extras are right because I stole them from someone else's source. How could I have found that out by myself?

Even looking at the source code, I can see the ClassName to use, as it's in AndroidManifext.xml as an action, but I'm not seeing anything that points me towards "pkg", which is apparently the appropriate Extra to be used for this with Froyo, the longer for previous versions.

+2  A: 

How do I determine the arguments (that is, Data, Extras, etc.) to send to an Intent?

If it is not documented, do not use it. The code you show is very fragile and may stop working with any new Android release. It might even fail on certain devices, if a device manufacturer decides (for whatever strange reason) to replace that portion of the Settings application.

CommonsWare
Good advice, but assuming I want to ignore it, in order to do something that seems otherwise impossible, what then? What should I be looking for?
wfaulk
Also, does not being listed in AndroidManifest.xml imply documentation?
wfaulk
"Also, does not being listed in AndroidManifest.xml imply documentation?" Of course not. Putting stuff in the manifest is a technical requirement of Android. It does not imply that the author of that application is interested in random third-party apps using those things. Documentation is how an application developer tells others of supported APIs. If a developer wants you to call its activities directly, the developer will tell you how. In the case of Android apps (e.g., Settings), the developer documentation is very distinct from the source code.
CommonsWare