Say you want to open fuelgauge in Android 1.6, to do this.
final Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.fuelgauge.PowerUsageSummary");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity( intent);Explanation
To open other people's application, you need to make sure that in their manifest file, the author specify the class to have the android.intent.action.MAIN intent-filter added to them.
final Intent intent = new Intent(Intent.ACTION_MAIN, null);
We then add category that this new intent will be launching something
intent.addCategory(Intent.CATEGORY_LAUNCHER);
Then we get identify the application we need to open by using ComponentName, here you specify the package name of the application as first argument and the class we want to open as the second one. You must understand that com.android.settings has a lot of classes that have Main intent-filter under it making the second argument to be the specific class that we need. (this is more than one line)
final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.fuelgauge.PowerUsageSummary");
After we identify the component we want, we set it to our intent
intent.setComponent(cn);
We then tell the intent that open opening this one make it as a new task
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Then finally start our intent
startActivity( intent);
Resources
LauncherProvider.java
IRC #android-dev room
9 comments:
Hi! Thank u first for ur tutorials, they going to help me a lot to start with Android.
By reading this one a question comes to me.
How could i re-use the activity in the home screen that lists applications with a slide effect when draging it with fingers ?
Thx!
Thanks, glad its helping you :) By reuse you mean using the one from google? I think its better if you get the idea on how the staff is being done first before reusing any codes, btw most of the sources on launching staff (like applications, widget, etc) could be found on the official Launcher.git (http://android.git.kernel.org/?p=platform/packages/apps/Launcher.git;a=tree;f=src/com/android/launcher;h=86727674d25930f667f644a76c2478a35e13b0f2;hb=154f4a3dcc3ebb07fa7db51d3ff57a1557990cc0)
Thank you for your answer.
Well by reuse i mean using in part the one from Google as a view component that could be binded with a object list...
In the same idea i'm interested of use android live folders..like a real folder where i could drag items but it seems like not easy to do.
Anyway! i'm going first to get Android source code and try to get how they do it
Hello,
Thank you for this valuable info.
So, in order to open other people’s application,
we need to know both the package and class names.
Correct? I would like to confirm it.
Thank you again!
Sorry, but I forgot one question.
What if I just have a package name?
Is there any way to know the class(es)?
Thanks,
If you just know the package name then you could use PackageManager and use getPackageInfo :)
Wow, thank you for the additional info!
I will definitely try this.
Best regards,
Hi friends,
Nice Tutorial...thanx lot.
I have a quest ,how can i hide a particular install application name from install application name list.
Thanks in Advnace
It is really great! Thanks so much!
Post a Comment