Is it possible to install an apk without user intervention, putting commands from the prompt in the code or something?

0

Actually, it's the update I need to do, does anyone know if it's possible to do this without user intervention? I just report that there is an update closing the application and updating itself. Thank you in advance.

    
asked by anonymous 02.06.2016 / 15:49

1 answer

0

This is only possible with robotic devices.

    public static boolean InstallAPK(String filename)
    {
        File file = new File(filename);
        if(file.exists())
        {
            String path = file.getAbsolutePath().replace(" ", "\ ");
            try
            {
                String[] command = new String[]
                        {
                                "/system/bin/su",
                                "-c",
                                "pm install -r " + path
                        };
                String[] command2 = new String[]
                        {
                                "/system/xbin/su",
                                "-c",
                                "pm install -r " + path
                        };
                String[] command3 = new String[]
                        {
                                "su",
                                "-c",
                                "pm install -r " + path
                        };
                Process proc;
                try
                {
                    proc = Runtime.getRuntime().exec(command);
                    BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
                    int res = proc.waitFor();
                    String todo = "Resultado do Processo:";
                    String line;
                    while((line =  br.readLine()) != null)
                    {
                        todo += "\n"+line;
                    }
                    if(res == 0 && todo.contains("Success"))
                    {
                        return true;
                    }
                    if(res == 0)
                    {
                        proc = Runtime.getRuntime().exec(command2);
                        br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
                        res = proc.waitFor();
                        todo = "Resultado do Processo:";
                        while((line =  br.readLine()) != null)
                        {
                            todo += "\n"+line;
                        }
                        if(res == 0 && todo.contains("Success"))
                        {
                            return true;
                        }
                        if(res == 0)
                        {
                            proc = Runtime.getRuntime().exec(command3);
                            br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
                            res = proc.waitFor();
                            todo = "Resultado do Processo:";
                            while((line =  br.readLine()) != null)
                            {
                                todo += "\n"+line;
                            }
                            if(res == 0 && todo.contains("Success"))
                            {
                                return true;
                            }
                        }
                    }
                    AddLog("SiletlyInstall", "Erro numero: "+res+"\n\nLog de Instalação:\n"+todo);
                    return false;
                }
                catch (Exception e1)
                {
                    save(e1);
                }
            }
            catch (Exception e)
            {
                save(e);
                return false;
            }
        }
        AddLog("SilentlyInstall", "Arquivo não existe :: "+filename);
        return false;
    }
    
03.06.2016 / 23:33