Http://www.2cto.com/kf/201203/122910.html
There is an API in the Android SDK:
Public abstract Intent Getlaunchintentforpackage (String packagename)
If the PackageName exists to return to the Ingress Intent, StartActivity (Intent) can start the application, otherwise return nullimport android.app.Activity;
Here's a small example:
[Java]View Plaincopy
- Import android.content.Intent;
- Import Android.content.pm.PackageInfo;
- Import Android.content.pm.PackageManager;
- Import Android.os.Bundle;
- Import Android.view.View;
- Public class Main extends Activity {
- /** Called when the activity is first created. * /
- @Override
- Public void onCreate (Bundle savedinstancestate) {
- Super . OnCreate (savedinstancestate);
- Setcontentview (R.layout.main);
- Packagemanager Packagemanager = Getpackagemanager ();
- Intent intent=New Intent ();
- Intent =packagemanager.getlaunchintentforpackage ("Pkgname");
- if (intent==null) {
- System.out.println ("APP not found!" );
- }
- StartActivity (Intent);
- }
- }
- //-----Start the program we wrote------------------
- Mbutton01.setonclicklistener (new Button.onclicklistener () {
- Public void OnClick (View v) {
- //-----Core-----First Name a parameter is the package name of the application, and the latter is the main activity name of the application
- Intent intent=New Intent ();
- Intent.setcomponent (new componentname ("Com.droidnova.android.games.vortex",
- "Com.droidnova.android.games.vortex. Vortex "));
- StartActivity (Intent);
- }
- });
- //-----Start the application that comes with the system------------------
- Mbutton02.setonclicklistener (new Button.onclicklistener () {
- Public void OnClick (View v) {
- Intent intent=New Intent ();
- Intent.setcomponent (new componentname ("Com.android.calendar", " Com.android.calendar.LaunchActivity "));
- StartActivity (Intent);
- }
- });
This code is the main activity to start another application, and of course you can start any activity
ComponentName componetname = new ComponentName (
This is the package name of another application
"Com.poynt.weibo",
This parameter is the activity to start
"Com.poynt.weibo.ui.IndexActivity");
Android launches another app's activity in one app
Add a intent-filter definition for the activity.
The test finds that the activity can be called normally as long as the following statement is added:
<intent-filter>
<action android:name= ""/>
</intent-filter>
The corresponding startup code is:
Intent Intent = new Intent ();
Intent.setclassname (<package name>, <class name>);
StartActivity (Intent);