0

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>

更多相关文章

  1. Android第一个程序 Hello World
  2. Android中通过代码检测系统是否有root权限
  3. 参考注释郭霖老师的Android相机程序
  4. Android 判断程序是否在前台运行
  5. Android 代码片段---获取手机通讯录列表
  6. Android:BT测试代码
  7. Android控制台中运行Java程序
  8. Dialog弹出后 Activity蒙层效果代码
  9. android之sharedpreference读取参数

随机推荐

  1. 轻松解决Github连接缓慢、图裂问题
  2. Conda太慢?试试这个加速工具!
  3. 25页PPT | 如何利用python进行地图可视化
  4. 解决matplotlib文字标签遮挡问题
  5. 基于geopandas的空间数据分析—geoplot篇
  6. geopandas&geoplot近期重要更新
  7. 20 行代码:Serverless 架构下用 Python 轻
  8. 成天说要删库跑路,这次真的有人干了
  9. Python+Kepler.gl轻松制作时间轮播地图
  10. 必知必会的8个Python列表技巧