个人总结,以备不时之需!
在Android 程序中调用其他程序,主要是用Intent实现的
Intent 在一个程序中调用别的程序
=============================
1,不错,很经典,方法简单易懂
mIntent = SatelliteMenuActivity.this.getPackageManager().getLaunchIntentForPackage("com.android.factorytest");
mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(mIntent);
=============================
2,如何确定具体该调用哪个Action,可以在android命令终端中,执行“logcat -c ; logcat ”,点击你要运行的apk,看看系统是如何调用的,例如:
I/am_create_activity( 2532): [0,1100373216,50,com.android.gallery3d/com.android.camera.CameraActivity,android.media.action.STILL_IMAGE_CAMERA,NULL,NULL,335544320]
I/ActivityManager( 2532): START u0 {act=android.media.action.STILL_IMAGE_CAMERA flg=0x14000000 cmp=com.android.gallery3d/com.android.camera.CameraActivity} from pid 4377
mIntent = new Intent();
mIntent.setAction(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
startActivity(mIntent);
=============================
3,用ComponentName ,具体ComponentName中的pkg,cls为什么,可以在android命令终端中,执行“logcat -c ; logcat ”,点击你要运行的apk,看看系统是如何调用的,例如:
I/ActivityManager( 2532): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.gallery3d/com.android.camera.CameraLauncher} from pid 2725
mIntent = new Intent();
ComponentName cn = new ComponentName("com.android.gallery3d", "com.android.camera.CameraLauncher");
mIntent.setComponent(cn);
startActivity(mIntent);
=============================
4,由以上综合可有
mIntent = new Intent();
ComponentName cn = new ComponentName("com.android.mms", "com.android.mms.ui.ConversationList");
mIntent.setComponent(cn);
mIntent.setAction(Intent.ACTION_MAIN);
mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(mIntent);