Android中实现一个应用程序对另一个应用程序的调用

在app1中写下下面的一端代码:

       Intent tIntent = new Intent();
       ComponentName tComp = new ComponentName("app2.eagle", "app2.eagle.EagleZip");
       tIntent.setComponent(tComp);
       tIntent.setAction("Android.intent.action.MAIN");
       tIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

       startActivity(tIntent);

 

    在app1中的AndroidMenifest.xml中有这样的配置:

            <activity android:name="UI"
                 android:label="@string/app_name">
                 <intent-filter>
                     <action android:name="android.intent.action.MAIN" />
                     <category android:name="android.intent.category.LAUNCHER" />
                 </intent-filter>
                 <intent-filter>
                     <action android:name="UI" />
                      <category android:name="android.intent.category.DEFAULT"/>
                 </intent-filter>           
            </activity>

 

    在app2的AndroidMenifest.xml中下面的配置:

           <activity android:name="EagleZip"
                  android:label="@string/app_name">
                  <intent-filter>
                      <action android:name="android.intent.action.MAIN" />
                      <category android:name="android.intent.category.LAUNCHER" />
                  </intent-filter>
                  <intent-filter>
                      <action android:name="EagleZip" />
                      <category android:name="android.intent.category.DEFAULT"/>
                  </intent-filter>

            </activity>

相关推荐