Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Install Android apk from code in Unity

Discussion in 'Android' started by ms_gamer, Apr 13, 2021.

  1. ms_gamer

    ms_gamer

    Joined:
    Jun 8, 2019
    Posts:
    2
    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.
     
  2. BenniKo

    BenniKo

    Joined:
    Mar 24, 2015
    Posts:
    100
    You could do it by calling adb.exe
    Code (CSharp):
    1. adb install example.apk
     
  3. ms_gamer

    ms_gamer

    Joined:
    Jun 8, 2019
    Posts:
    2
    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.
     
  4. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    So you want to install a separate app, right? Not the app that's running, it's already installed.
     
  6. siddhuu

    siddhuu

    Joined:
    Jun 10, 2020
    Posts:
    3
    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!
     
  7. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,624
  8. siddhuu

    siddhuu

    Joined:
    Jun 10, 2020
    Posts:
    3
    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.
     
  9. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,624
    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
     
  10. siddhuu

    siddhuu

    Joined:
    Jun 10, 2020
    Posts:
    3
    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?