Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

android - One .apk file that installs two apps

This is a question concerning android applications with two different .apks (or two apps contained in the one .apk file)

I have two apps which do completely different things but are related, say one is a standard user app and one is an admin app. But a user can be both a user and an admin. I am wondering is it possible for me to create one .apk file that installs two applications to the phone? And how would I got about this?

Thanks, Matt

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can have two activity elements in the same manifest file, which have both the intent filter with action=MAIN and category=LAUNCHER. Further, you have also to use the attribute "android:taskAffinity" for both activity elements (see also here):

<application android:allowBackup="true"        
             android:icon="@drawable/main_icon"
             android:label="@string/main_name"
             android:theme="@style/AppTheme" >
             
    <activity android:name="com.foobar.MyActivity2"            
              android:taskAffinity="com.foobar.MyActivity2"
              android:icon="@drawable/icon1"
              android:label="@string/name1" >
        <intent-filter>
            <action   android:name="android.intent.action.MAIN"       />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>        
    
    <activity android:name="com.foobar.MyActivity2"
              android:taskAffinity="com.foobar.MyActivity2"
              android:icon="@drawable/icon1"
              android:label="@string/name2" >
        <intent-filter>
            <action   android:name="android.intent.action.MAIN"       />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>             
    
</application>

When the APK file with this manifest is installed on a device, then it will create two icons on the homescreen. The titles of these icons will be taken from the attributes android:label, and the icons will be taken from the attributes android:icon. In the list of apps under "Settings | Apps" you will see the name & icon defined by the attributes of the application tag. When you choose "uninstall" for this entry in the list of apps, then both "apps" will be removed from the device.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...