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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

HELP! How to uninstall android game of mine programically?

Discussion in 'Android' started by TritanTechnology, Dec 8, 2021.

  1. TritanTechnology

    TritanTechnology

    Joined:
    Feb 16, 2017
    Posts:
    19
    Hey, everyone! I have an android device, on which I have installed previously an apk which I cannot upgrade because it was done on another machine and with a debug keystore.

    Now I am wondering if I can uninstall the old one upon installing the new update on the device (as a new app with a different keystore). I would be very thankful if you can help me with this. I pretty much googled everything.

    Note: I found something with Intents and ACTION_DELETE, but I am not good with those android specific things.

    Thank you in advance!
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,516
    I haven't looked into this specifically, but I would be shocked if Android allowed you to delete one app from within another. Just imagine if apps could randomly delete each other at will... it'd be pretty dodgy from a security perspective.
     
  3. TritanTechnology

    TritanTechnology

    Joined:
    Feb 16, 2017
    Posts:
    19
    @angrypenguin this is what I worry about as well, but I was hoping that the fact that I am also the creator of the other app (so I am well aware of its package id, etc) would somehow allow me to bypass any security.
     
  4. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,516
    Being the creator doesn't really make it any more secure. Imagine: your computer gets hacked, and now the attacker can delete stuff from all of your customers' devices. No thanks!

    For that matter, I don't even want my app vendors deleting their own stuff from my device. License enforcement and safety are the only two reasons I can think of to stop people using stuff on their own devices, and neither require removing data.
     
  5. TritanTechnology

    TritanTechnology

    Joined:
    Feb 16, 2017
    Posts:
    19
    @angrypenguin I just wanted to share with you since it may be of help in the future - I found a way to do it. It was tricky for me in Unity because its suppose to be in a Java script, but here what worked -


    Code (CSharp):
    1.         AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    2.         AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
    3.         AndroidJavaClass intentObj = new AndroidJavaClass("android.content.Intent");
    4.         string ACTION_DELETE = intentObj.GetStatic<string>("ACTION_DELETE");
    5.         AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent", ACTION_DELETE);
    6.         AndroidJavaObject uriClass = new AndroidJavaObject("android.net.Uri");
    7.         AndroidJavaObject parsedUriString =
    8.             uriClass.CallStatic<AndroidJavaObject>("parse", "package:com.placeholder.placeholder");
    9.         intent.Call<AndroidJavaObject>("setData", parsedUriString);
    10.         currentActivity.Call("startActivity", intent);