Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 224
Shruti Avatar asked Sep 16 '11 02:09

Shruti


People also ask

Do APK files run automatically?

Apps downloaded from Google Play are automatically installed on your device, while those downloaded from other sources must be installed manually. Typically, users never see APK files because Android handles app installation in the background via Google Play or another app distribution platform.

Why does APK file not installing?

When you download an APK file from an unknown source, your Android phone will often show you an error message saying "App Not Installed". This is an additional security feature to prevent malware infection on your phone.


3 Answers

Have you tried adding the below permission?

<uses-permission
    android:name="android.permission.INSTALL_PACKAGES" />

Add the above code to your manifest (especially when you are getting security exception).

You can refer to Install apps silently, with granted INSTALL_PACKAGES permission

Hope this works for you.

like image 72
Jimmy Ilenloa Avatar answered Oct 18 '22 10:10

Jimmy Ilenloa


Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File("/mnt/sdcard/myapkfile.apk");
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);

The above code will install the myapkfile.apk. You just need to put this code in the onCreate() of the Activity.

like image 30
java dev Avatar answered Oct 18 '22 08:10

java dev


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);
like image 34
Femi Avatar answered Oct 18 '22 10:10

Femi