Louis
Louis

Reputation: 71

Split Android app in two parts

I'm trying to understand if it is possible to split an Android App into two parts (installed from one APK). I looking into this to install one part on the Device memory and the other part on the SD-CARD. The two parts belong together and should not be installed separately.

Note: I need to separate not only resources, but also activities, so APK Expansion Files not a solution, because not provide such functionality.

Upvotes: 7

Views: 5174

Answers (8)

Mohd Asim Suhail
Mohd Asim Suhail

Reputation: 2302

You can create two different launching activities from one APK by defining two MAIN LAUNCHER entries in Manifest.xml

<activity android:name=".ChooserActivity"
            android:label="Auth Firebase">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <activity android:name=".GoogleSignInActivity"
            android:label="Auth Google"
            android:installLocation="preferExternal">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

this will create two entry points for an app, two different launcher icons one named "Auth Firebase" and other named "Auth Google" both will open different activities.

Upvotes: 0

Christian Strempfer
Christian Strempfer

Reputation: 7383

If you're just looking for a way to keep application resources on the external drive, Harry's answer will be useful.

Otherwise it's not possible to split one app installation into two parts. You can use the android:installLocation manifest attribute to define where you want to install it and you can even force it to only install internally on the device, but there is no option to split it.

Alternatives

Two Apps

You create two separate two apps and check on start of any of them, if the other one is installed. If not, you ask the user to install the other one and forward the user to the app store.

One app checks the external storage

I don't know your use case, but from your comments it sounds like you're looking for the wrong solution.

The application I'm thinking about has one part that I want always to be available (install on device memory) and one part that the user may make unavailable (temporary) by removing the SD-CARD. Also when the user decides to move the app to or from the SD-CARD, the part that I want installed in device memory should always stay there.

You can just check if the external storage is available and block certain activties if it's not. If you want to make sure, it's the same SD card you can create a UUID on first run and save it both internally and externally. If they match it's the correct SD card.

Conclusion

Your solution probably is too complicated and you should look for alternatives.

Upvotes: 0

Harry
Harry

Reputation: 937

Maybe is this what you want? APK Expansion Files

Upvotes: 0

Davek804
Davek804

Reputation: 2804

You can, but not for your reason. Multiple APKs are just to ensure your app works for multiple devices - not to divide up its total size between internal memory and SD card.

Multiple APK Support

Although we encourage you to develop and publish a single APK that supports as many device configurations as possible, doing so is sometimes not possible. To help you publish your application for as many devices as possible, Google Play allows you to publish multiple APKs under the same application listing. Google Play then supplies each APK to the appropriate devices based on configuration support you've declared in the manifest file of each APK.

By publishing your application with multiple APKs, you can:

Support different OpenGL texture compression formats with each APK.

Support different screen configurations with each APK.

Support different platform versions with each APK.

Currently, these are the only device characteristics that Google Play supports for publishing multiple APKs as the same application.

Upvotes: 0

W4R10CK
W4R10CK

Reputation: 5550

APK Expansion Files

Google Play currently requires that your APK file be no more than 100MB. For most applications, this is plenty of space for all the application's code and assets. However, some apps need more space for high-fidelity graphics, media files, or other large assets. Previously, if your app exceeded 100MB, you had to host and download the additional resources yourself when the user opens the app. Hosting and serving the extra files can be costly, and the user experience is often less than ideal. To make this process easier for you and more pleasant for users, Google Play allows you to attach two large expansion files that supplement your APK.

Google Play hosts the expansion files for your application and serves them to the device at no cost to you. The expansion files are saved to the device's shared storage location (the SD card or USB-mountable partition; also known as the "external" storage) where your app can access them. On most devices, Google Play downloads the expansion file(s) at the same time it downloads the APK, so your application has everything it needs when the user opens it for the first time. In some cases, however, your application must download the files from Google Play when your application starts.

Downloading the Expansion Files

In most cases, Google Play downloads and saves your expansion files to the device at the same time it installs or updates the APK. This way, the expansion files are available when your application launches for the first time. However, in some cases your app must download the expansion files itself by requesting them from a URL provided to you in a response from Google Play's Application Licensing service.

The basic logic you need to download your expansion files is the following:

When your application starts, look for the expansion files on the shared storage location (in the Android/obb// directory). If the expansion files are there, you're all set and your application can continue. If the expansion files are not there: Perform a request using Google Play's Application Licensing to get your app's expansion file names, sizes, and URLs. Use the URLs provided by Google Play to download the expansion files and save the expansion files. You must save the files to the shared storage location (Android/obb//) and use the exact file name provided by Google Play's response.

Source

Upvotes: 1

Shrikant Ballal
Shrikant Ballal

Reputation: 7087

I think it will be possible. Can you try following approach?

  1. Create two apps
  2. In the Manifest file of first APK, you should have an Activity that is of MAIN and LAUNCHER category. This way your app will be visible in the Launcher list
  3. You should not have any Activity of MAIN and LAUNCHER category in 2nd APK, but you know which Activity you have to open as Launcher Activity of second app as it's your own app. This way your second app will never show up in Launcher list of apps
  4. Put 2nd APK in assets folder of first APK
  5. Whenever your main app wants to use contents from 2nd app, install 2nd app from assets folder (as mentioned here) with setting the install location on SDCard like this: android:installLocation="preferExternal" and then launch your desired activity of second app

I've not tried this yet but theoretically seems legit.

Let me know if this works. Thanks!

Upvotes: 4

Fco P.
Fco P.

Reputation: 2701

Yeah, it's possible. But with a caveat, it would be possible to install both apps separately, since both of them should be uploaded to the store. You just need to use a lot of intents.

You'll need to handle all communications between both apps using intents. That means, everything the first app needs must be asked using an intent to the second app, and failing to find the other app within the device should trigger an intent to the play store. This way, you'll have two apps working like one. Keep in mind, the user is still going to determine where to install your app, but as christian-strempfer pointed, the SD card can be set as the preferred target.

If the purpose of this is saving space, you should make your resources (images, sounds, etc) dynamic. Since all of those are just files inside the apk, you could easily replace them with files from the SD-Card. You just need to upload them somewhere and download them after the app is installed. That way, you could provide the exact versions of each asset and remove them when you need. You could learn which screens are most used and remove the assets for the ones you use less. Etc.

Upvotes: 0

jdstaerk
jdstaerk

Reputation: 892

Your app could just check wether the sd card is currently available ("plugged-in") or not. If it is available your app works like normal and if the sd card is not available the app would automatically quit / show a pop-up / launch different activities / whatever.

Upvotes: 0

Related Questions