1

I have two separate apps. Currently I am able to install them separately. I wanted to find out how I can install them using a single APK.

I want to be able to have both apps still run independently of each other but I wanted to be able to package them together.

This way when a user goes to the google play store they see one app, but it actually install both the apps.

Thanks, Jeff

Jeff
  • 19
  • 1
  • 2
  • 2
    "I want to be able to have both apps still run independently of each other" -- please explain **in detail** what this means from a technical standpoint, and what the difference would be if all of this functionality were in one app. – CommonsWare Jun 20 '17 at 18:58
  • The first application is an app that converts documents to pdfs. The second application is a print service. Both run independently of each other. They are independent applications. In Google play store, I want them to show up as the name of the first application. When the first application is downloaded and installed, I would like both applications installed. – Jeff Jun 20 '17 at 19:07
  • 1
    "They are independent applications" -- why? Again, what is the *technical reason* for the separation? What you want is not possible, for obvious reasons (in your scenario, replace "print service" with "malware"). In fact, IIRC, what you want is against the terms of service for the Play Store for this reason. So, while technically you could have an APK inside your APK, then extract and install it (after the user grants your app the right to install other apps, then proceeds through the installation screens for the 2nd APK), it is unclear why this is in the best interests of you or your users. – CommonsWare Jun 20 '17 at 19:18
  • I have seen another app that exhibits this behavior. I install their single app and it install the app and a print service. The app does a single download and install and does not show a second app being installed as part of the process. After the install of the app, there is an icon for the app and when I go to the print services settings, I see that they have installed a print service as well. I wanted to be able to follow that same convention. – Jeff Jun 20 '17 at 20:34
  • Nothing in your description implies two apps. What you describe would be the expected results for a single app that happens to have both a launcher activity and a print service. – CommonsWare Jun 20 '17 at 20:36
  • Sorry for the confusion. I should have said activity and print service instead. I am new to mobile app development and android. I apologize for the confusion. Currently I am installing the print service and the launcher activity separate. I would like to be able to install both together. – Jeff Jun 20 '17 at 21:54
  • "I would like to be able to install both together" -- then put them both in one app. – CommonsWare Jun 20 '17 at 21:55

3 Answers3

1

you can define 2 luncher activity in your manifest file like bellow the result is what you want:

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
        android:icon="@mipmap/ic_launcher">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity2"
        android:icon="@mipmap/ic_launcher">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
faraz khonsari
  • 1,924
  • 1
  • 19
  • 27
  • This is working for me. I have created two app and after migrate first app on second app as library. Next remove the `intent-filter` from library's `AndroidMenifest.xml` file and problem is solved. Thank you. – Ninja May 18 '20 at 04:51
1

You cannot just install two apps directly without showing the user, the thing that you can do is to create a new app in which you will put your 2 apk files in the "raw" folder inside build folder. And push them to open together, those app will show a dialog to user to ask about permissions and will be installed if user allows.

Here is the code to do that:

 for (int a=0;a<names.length;a++)
    {
        InputStream in = null;
        OutputStream out = null;
        try {
            in = getBaseContext().getResources().openRawResource(array[a]);  // Here "array" is actually and array holding the reference of apk files (eg. R.raw.firstApp)
            out = new FileOutputStream(Environment.getExternalStorageDirectory().getPath()+"/"+names[a]+".apk");  // Here "names" is an array holding the names of your apk files (eg. "firstApp")
            Log.e("Path" ,Environment.getExternalStorageDirectory().getPath());
            byte[] buffer = new byte[1024];
            int read;
            while((read = in.read(buffer)) != -1){
                out.write(buffer, 0, read);
            }
            in.close();
            in = null;
            out.flush();
            out.close();
            out = null;
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath()+"/"+names[a]+".apk")), "application/vnd.android.package-archive");
            startActivity(intent);
        }catch(Exception e){
            // deal with copying problem
        }
    }
Zohaib Hassan
  • 984
  • 2
  • 7
  • 11
0

Thank you for the advice. I was able to solve the issue by following, note I am leaving out the https part since I am unable to post links: Create a main activity project. Create another project for a service. Convert the service application to a library: developer.android.com/studio/projects/android-library.html#AddDependency

Fix any merge manifest issues: developer.android.com/studio/build/manifest-merge.html stackoverflow.com/questions/39178764/how-to-add-more-than-one-toolsreplace-in-android-manifest-application developer.android.com/studio/build/manifest-merge.html#inspect_the_merged_manifest_and_find_conflicts

Update the proguard-rules.pro files: -keepattributes EnclosingMethod

-Error in gradle build after updating Android Studio with log4j

Add a dependency to the main activity application in gradle: Compile project (':myserviceapp')

Jeff
  • 19
  • 1
  • 2