您的位置:首页 > 移动开发

怎么在一个APP中调用另外一个APP

2016-06-07 16:26 281 查看
        声明:下文中把去调用的APP称谓A,把被调用的APP称谓B。

        首先在B中的清单文件中找到A调用时需要进入到的activity,并把在属性中增加:

<pre class="html" name="code"><pre class="html" name="code"><activity
android:name="org.ebookdroid.pdfdroid.activity.MainFunctionActivity"
android:hardwareAccelerated="true"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar"
<span style="color:#ff0000;"><strong>android:exported="true"</strong> </span>>
<intent-filter>
<action android:name="<strong><span style="color:#ff0000;">com.esa2000.azt.asignon1.startViewer</span></strong>" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>


     然后在A中的activity中去调用这个action。


    即

Intent intent = new Intent("com.esa2000.azt.asignon1.startViewer");
intent.putExtra("name", str1);
intent.putExtra("password", str2);
startActivity(intent);


如果不需要带参数的话,就不需要加上

intent.putExtra("name", str1);
intent.putExtra("password", str2);
在B的MainFunctionActivity中getIntent()就能获得参数。
 
另外,如果想在手机桌面只显示A而不显示B,则需要在B的清单文件中把跳入到的activity中属性<category android:name="android.intent.category.LAUNCHER" />给改成<category android:name="android.intent.category.DEFAULT" />。
 
还有想在同一部手机中既能安装B的本身APP,又能安装A调用的B,则需要把被调用的APP也是B中的包名给改掉。
例如B本身的包名为<manifest xmlns:android="<a target=_blank href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>"
    <strong><span style="color:#ff0000;">package="com.example</span></strong>"
    android:versionCode="1"
    android:versionName="1.0" >

改成为<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.test"

    android:versionCode="1"

    android:versionName="1.0" >。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息