How to determine the expected arguments for an Android Intent?
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 Appli开发者_JAVA技巧cation 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 Extra
s 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.
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.
精彩评论