在一個apk中調用另外一個apk中的activity
一、生成一個要被調用的APK。在其Manifest.xml設置中,與一般的寫法大致相同,唯一區別的地方在于,如下:
<activity android:name="com.example.test.TestActivity" 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="testApp"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>
二、安裝這個要被調用的APK。
安裝完畢之后,你會發現,系統中找不到這個程序。別急,它確實安裝在手機里面了,但是因為他不是main的,所以系統不會把他當做Application的入口程序。而要想打開這個activity,只有知道它名字的人才可以。跟系統的intent一樣使用。它的名字定義為"testApp",所以,這里用這個字符串就可以調用它了:
三、在另一個項目中調用上述APK。代碼如下:
Intent intent = new Intent("testApp"); startActivity(intent);
四、啟動另外一個apk
Intent mIntent = new Intent( ); ComponentName comp = new ComponentName(packageName, activityName); mIntent.setComponent(comp); mIntent.setAction("android.intent.action.VIEW"); startActivity(mIntent);
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!