Android install application from application

Download and Install APK Programmatically

Hello guys, as per title in this post I ‘ll tell you how to download the app using a download manager and install it programmatically. For doing that will create a sample app, for more detail you can watch feature video as well. So let’s get started

Download and Install APK (Demo APP)
Create a new Project

Open Android Studio and create a new android project with any default template. Once project sync is finished, open app-level build.gradle. In this android example we’ll use Snackbar for that we have to add material io dependencies. so let’s do that

Add uses permission

I’m going to download the APK file so we need storage permission and Internet permission. Once the app is download successfully than we will install it programmatically. For doing that we must need REQUEST_INSTALL_PACKAGES permission. Let’ s all needed permission in android manifest.

Create a file provider

You guys, already aware that in android N or above we have to write a file provider. Let’s create a resource file inside res=>xml=> named is file_provider_paths.xml

Now declare the file provider inside the manifest
Add some value inside strings.xml file
Create a download controller

Let’s create a file named is DownloadController, It’s controller is responsible to download file install it. This DownloadController we are using download manager for downloading APK.

Open the main activity layout file add one button
Create an extension file

For better coding practice, removing boilerplate code. We’ll write few extensions for AppCompatActivity and Snackbar. let’s create extension file and paste below code

Читайте также:  Части андроида matter overdrive
Open main activity file

Let’s open the file and paste the below code. In this activity, we are checking storage permission first. If permission is granted than calling download function otherwise requesting for storage permission.

Conclusion

All done, In this tutorial, we have learned how to download APK and Install it programmatically. I hope it’s helpful for you, Help me by sharing this post with all your friends.

Get Solution Code

Keep in touch

If you have any queries, feel free to ask them in the comment section below. 🙂

Источник

Оцените статью