19

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

MattTheHack
  • 1,354
  • 7
  • 28
  • 48

5 Answers5

14

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.

user1364368
  • 1,474
  • 1
  • 16
  • 22
  • how do i merge the two apks to make them into a single app – Sagar Devanga Dec 08 '14 at 09:48
  • "Merging two APKs" means that you do not have the source code of the apps, doesn't it? This question is discussed there: http://stackoverflow.com/questions/5074695. The problem is that for this you had to merge the two classes.dex, and also the AndroidManifest.xml, which is contained in binary form in the APK file. – user1364368 Dec 12 '14 at 14:21
  • i am trying to create an app like LOCKET so i have an apk for LockScreen since i have made it LAUNCHER in the manifest and i have an apk for MainScreen inside the app which is also Launcher in my manifest. I have only one manifest file thats why i get 2 apks on the launcher. – Sagar Devanga Dec 13 '14 at 07:16
7

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

Nanne
  • 64,065
  • 16
  • 119
  • 163
  • Just solution sounds like it would suit...do you have a link to it on the Android developers wiki, I can't see it, thanks – MattTheHack May 21 '12 at 09:39
  • Sure: http://developer.android.com/guide/topics/manifest/activity-element.html . You are declaring every activity anyway, so it's no big deal really. You should have an intent-filter for it being a launcher, just like your first activity: http://developer.android.com/reference/android/content/Intent.html#CATEGORY_LAUNCHER – Nanne May 21 '12 at 09:48
2

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

Project Structure:

enter image description here

Kumar Roshan Mehta
  • 3,078
  • 2
  • 27
  • 50
1

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

Btw, this is a security measure.

shkschneider
  • 17,833
  • 13
  • 59
  • 112
0

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.

thepoosh
  • 12,497
  • 15
  • 73
  • 132