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>
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.
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.
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With