MattTheHack
MattTheHack

Reputation: 1384

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

Upvotes: 19

Views: 31062

Answers (5)

user1364368
user1364368

Reputation: 1564

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.

Upvotes: 14

Kumar Roshan Mehta
Kumar Roshan Mehta

Reputation: 3306

Yes, you can install multiple apps by just installing one app.
In Manifest.xml enter image description here

Project Structure:

enter image description here

Upvotes: 2

Nanne
Nanne

Reputation: 64399

It depends on your definition of "application". You cannot install 2 applications if you use the more official definition, as you can have only 1 <application> in your manifest.xml

You can define several activities in your manifest.xml, and they can do seperate things, so in that way YOU CAN have 2 things a person might describe as "application" in one APK

Just define multiple activities and use those could be defined as an option, but it depends on your definition of 'application', but in this case I'd say it would work

Upvotes: 7

thepoosh
thepoosh

Reputation: 12587

No.

what you can do is to check if the second app is already installed, and if the answer is no, you can prompt the request to install the second app using this post.

Upvotes: 0

shkschneider
shkschneider

Reputation: 18243

You should either build 2 APKs are use APK Expansion Files.

Btw, this is a security measure.

Upvotes: 1

Related Questions