Install Android apk from code in Unity

Hi, I need help to develop a feature that allows me to install/uninstall the app within my unity app. How I can achieve this by writing code in unity or how can I create an external library or plugin for the same. Any help will be much appreciated.

You could do it by calling adb.exe

adb install example.apk

Hi @BenniKo , Thanks for the quick help. But what I want is to install the app within my unity app. So lets say I have there will be one button of install in my app & by clicking on it .apk is which is stored in my device will be installed in my phone. It is kind of what the play store does for installing the app. Can you please guide me for the same?

Thanks in Advance.

So you want to install a separate app, right? Not the app that’s running, it’s already installed.

I have a similar query, I am downloading an apk from my Unity App and after the download completes, I want to install the new apk onto my android device. The device in question is the Meta Quest 2 HMD and I’ve been unable to find an answer! Would love some insight if possible!

I think what you’re looking for is similar to this: Android: Open saved file in default app from my app - Stack Overflow

It’s Java code to open a file using default app. It should open the .apk file using Google Play, which should ask if you want to install it. You can access Java from Unity using AndroidJavaObject API.

Though it’s probably better to submit app to store and use deeplinking.

Thanks for the prompt reply! Unfortunately, I haven’t been able to understand how to apply the top answer to the C# code. Would it be possible for you to dumb it down for me? I just want to know how to install an apk (the name is app2.apk) that I have downloaded into the Application.persistentDataPath using the app which I have made. I do not know much and I am a little rusty with my C# and android development.

For starter, you can’t literally install it. The code I linked would trigger the .apk file to be opened in a default app, like Google Play, from where the user would have to manually install it, getting warnings about untrusted source etc.
If what you want is to literally install app - you can’t.

A few samples on how to use AndroidJavaObject/AndroidJavaClass can be found here: https://docs.unity3d.com/2022.2/Documentation/Manual/AndroidJARPlugins.html

Okay, so I get what you are saying now. I have another file manager (CX File Explorer) installed on the HMD so is it possible for me to specifically use this file manager app to open the apk I have downloaded so I can install it?