Search code examples
androidinstallationdownload

How to install APK automatically when the file download is complete (hosted on private)


I am new to android and i have been searching the web from last two days for this. I found following links too but i am not getting how and where to implement this code to start automatic installation of the apk file after it downloads completely and how to delete the downloaded apk file after installation. Please help me by guiding me the right way.

how to install apk file programmatically

Invoking activity from APK in another android application

Android install apk programmatically

Install APK programmatically on android

http://www.anddev.org/viewtopic.php?p=23928

EDIT :

i have written this code in manifest file :

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <!-- <uses-permission android:name="android.permission.INSTALL_PACKAGES"/> -->
    <application android:icon="@drawable/biz_logo"
        android:permission="android.permission.WRITE_CONTACTS">
        <activity android:name="com.biz.mlm.Main">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="content" />
                <data android:scheme="file" />
                <data android:mimeType="application/vnd.android.package-archive" />
            </intent-filter>
        </activity>

Solution

  • Not possible. As some of those links point out, making an APK that automatically installs itself and deletes the original installer without any further user intervention is called malware.

    You can write a program that will download and install arbitrary APKs if the user grants it the relevant permissions, but I'm yet to see a good implementation or documentation for this. Typically you can invoke the default system installer using code like this:

    File apkFile = new File({path to APK});
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
        startActivity(intent);