Android 程序中调用其他程序的方法总结

个人总结,以备不时之需!


在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);

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值