Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app update automatic and silently?

Tags:

android

root

I develop an app and want update itself and want following fetures, device have been rooted :

1 automatic check can update every start (I can do)
2 download the apk file to local (I can do)
3 update with custom dialog, or update silently (I dont know )

edit: My app run on TV with remote, the default dialog which can control but perfect , so I want use my dialog if there must a dialog.Its best if need not a dialog.

like image 713
BollMose Avatar asked Dec 07 '25 08:12

BollMose


1 Answers

First declare this variables, then call function wherever you want. Then grant superuser, on your superuser application, check the option to always grant, for non user interaction.

  @Override
  public void onCreate() {
    super.onCreate();
            //some code...
             final String libs = "LD_LIBRARY_PATH=/vendor/lib:/system/lib ";

             final String commands = libs + "pm install -r " + "your apk directory"+ "app.apk";

             instalarApk(commands); 
 }

   private void instalarApk( String commands ) {
    try {

        Process p = Runtime.getRuntime().exec( "su" );
        InputStream es = p.getErrorStream();
        DataOutputStream os = new DataOutputStream(p.getOutputStream());

        os.writeBytes(commands + "\n");

        os.writeBytes("exit\n");
        os.flush();

        int read;
        byte[] buffer = new byte[4096];
        String output = new String();
        while ((read = es.read(buffer)) > 0) {
            output += new String(buffer, 0, read);
        }

        p.waitFor();

    } catch (IOException e) {
        Log.v(Debug.TAG, e.toString());
    } catch (InterruptedException e) {
        Log.v(Debug.TAG, e.toString());
    }
}
like image 92
AndersonCanteiro Avatar answered Dec 08 '25 22:12

AndersonCanteiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!