0

Na verdade, é atualização que preciso fazer, alguém sabe se é possível fazer isso sem intervenção do usuário? Eu apenas informar que há uma atualização fechar o aplicativo e atualizar sozinho. Agradeço desde já.

1 Resposta 1

0

Só é possível em aparelhos rotiados.

    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;
    }

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .