Is it possible to install an apk without user intervention by putting prompt commands in the codeword or something?

Asked

Viewed 50 times

0

Actually, it’s update I need to do, does anyone know if it’s possible to do this without user intervention? I just inform that there is an update close the application and update alone. I thank you from now.

1 answer

0

Only possible on routine 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;
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.