打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Android在自己的程序中调用外部程序

public void invokeCamera() {
  Intent mIntent = new Intent();
  ComponentName comp = new ComponentName(

                         "com.android.camera",
                         "com.android.camera.Camera");
  mIntent.setComponent(comp);
  mIntent.setAction("android.intent.action.VIEW");
  startActivity(mIntent);
}

ComponentName("","")中第一个参数是包名 ,第二个参数是启动程序 的类名 

====================================

 

1 .使用自定义Action[recommended] 

A程序中调用的代码为:
Intent intent = new Intent();
intent.setAction("com.test.action.PLAYER");               
startActivity(intent);

B程序(被调用)中的AndroidManifest.xml中启动Activity的intent-filter:
<intent-filter>
                <action android:name="android.intent.action.MAIN" />
                 <action android:name="com.test.action.PLAYER" />
                 <category android:name="android.intent.category.DEFAULT" /><!--必须,否则无效-->
                <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>



2 .使用包类名
A程序中调用的代码为:
Intent intent = new Intent();
intent.setClassName("com.test", "com.test.Player");
startActivity(intent);
intent.setClassName(arg1,arg2)中的arg1是被调用程序B的包名,arg2是B程序中目的activity的完整类名。

又或者:
Intent intent = new Intent();         
ComponentName comp = new ComponentName("com.test", "com.test.Player" ); 
intent.setComponent(comp); 
startActivity(intent);


B程序(被调用)中的AndroidManifest.xml中启动Activity的intent-filter不需要特别加入其它信息,如下即可:
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

http://blog.csdn.net/vincent_czz/article/details/5699945
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
关于Intent的七大属性
Intent
Android开发中Intent类的putExtra和setData 区别
Android Intent机制实例详解
intent打开外部程序、setClassName和 ComponentName 区别
Intent跳转到系统应用中的拨号界面、联系人界面、短信界面及其他 | 老焦的小窝
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服