外部程序调用应用Activity方法简介
2014-09-15 16:32
453 查看
如果想要在一个程序中,打开另外一个应用的Activity(例如在音乐播放页面打开音效Eq控制页面),就需要调用到此方法。
1、使用自定义的Action
A程序中的代码为:
B程序中的AndroidManifest.xml中启动Activity的intent-filter:
A程序中调用的代码为:
或者代码也可以这样写:
1、使用自定义的Action
A程序中的代码为:
Intent intent = new Intent(); intent.setAction("com.test.action.PLAYER"); startActivity(intent);
B程序中的AndroidManifest.xml中启动Activity的intent-filter:
<intent-filter> <span style="white-space:pre"> </span><action android:name="android.intent.action.MAIN" /> <span style="white-space:pre"> </span><action android:name="com.test.action.PLAYER" /> <span style="white-space:pre"> </span><category android:name="android.intent.category.DEFAULT" /><!--必须,否则无效--> <span style="white-space:pre"> </span><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> <span style="white-space:pre"> </span><action android:name="android.intent.action.MAIN" /> <span style="white-space:pre"> </span><category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
相关文章推荐
- Android中外部程序activity调用本地程序的app方法。
- 调用外部程序的方法
- Java调用外部程序的方法
- qt调用外部程序的方法 qprocess
- VC中调用外部程序的几种方法
- delphi程序参数的使用与java调用外部程序方法
- c#调用外部程序方法
- 转:VC调用外部程序的方法
- 在程序中调用外部程序,用process返回命令执行结果以及抓取错误信息的方法
- Android应用开发多个activity完全退出程序方法
- QT中调用外部程序的方法
- 关于用外部程序调用Informatica Workflow的方法
- QT中调用外部程序的方法 QProcess类
- flex air应用程序在windows环境下调用外部exe程序的一种方法
- SilverLight浏览器交互之:SilverLight程序调用外部Html中的Javascript方法(附源码)
- Shark中调用外部程序的方法
- QT中调用外部程序的方法 QProcess类
- Python调用外部程序的四种方法
- C# Shell 调用外部程序方法
- C # 调用外部程序方法