Android App Update Library can be used for downloading the Apk from a link , Save it to External or Internal Storage, Than automatic installing the apk. Remember to add provider xml and android runtime permission before using this library. See sample use in app folder.
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.Piashsarker:AndroidAppUpdateLibrary:1.0.1'
}
Remember to add below permission in Manifest.xml file
. And Also add runtime permission for (Version => Marshmallow ). See the sample app.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Create a folder called xml
in res
folder. Create a xml file and named it provider_paths
. Paste below code:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
Add below code in your manifest.xml
file.
<application
..............
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>
After setting up all neccessary files it's just two line of code to download and install the apk updates in your device.
String url = "http://androidpala.com/tutorial/app-debug.apk";
DownloadApk downloadApk = new DownloadApk(MainActivity.this);
downloadApk.startDownloadingApk(url);
You are Good To Go. Happy Coding