androidinstallationapkexternal-application

How do I Install external APKs necessary for my application in Android Studio?


I have downloaded CSipSimple . Now for video call of this , I need to install CSipSimple-Codec-Pack and CSipSimple-Video-plugin apks . I need to install these two external apks with my Android application . These apks are necessary for installation of my application .

How can I install these apks with my Android application by programming ?


Solution

  • there are 2 ways you could try this

    The 1st one only works when phones have sdcards, the 2nd one is simpler its more straight forward There is no code for this I assume you know how to get the source code of the applications you need right? just copy paste them into your application's root folder, then in android studio right click your project mouse over new-> click on module -> import gradle project -> then select the required application.

    For the 1st method take a look at this thread

    Code Snippet:

    AssetManager assetManager = getAssets();
    
    InputStream in = null;
    OutputStream out = null;
    
    try {
        in = assetManager.open("myapk.apk");
        out = new FileOutputStream(Environment.getExternalStorageDirectory()+"/myapk.apk");
    
        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()+"/myapk.apk")),
            "application/vnd.android.package-archive");
    
        startActivity(intent);
    
    } catch(Exception e) { }
    

    The above code copies apk from your assests folder to sdcard, then installs it on the phone.