I cannot read the first url line

Asked

Viewed 56 times

0

Good night. Although I can’t figure out which error I can’t get the first line of the file that is in the url when this application is used by versions higher than api 10 because api 10 works well. because it will be?

Integer valor;
TextView texto;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    texto = (TextView)findViewById(R.id.BarraTextView);
    texto.setText("Verificando novas atualizações");
    try {
        valor = getUrlContents("http://exemplo/versao.txt");
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (valor > 111)
    {
        AlertDialog.Builder confirma = new AlertDialog.Builder(this);
        confirma.setTitle("Aviso");
        confirma.setMessage("Existe uma nova versão deseja atualizar agora?");
        confirma.setPositiveButton("Sim", new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialogInterface, int i)
            {
                Intent DownloadIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://exemplo/aplicacao.apk"));
                startActivity(DownloadIntent);
                System.exit(0);
                finish();
            }
        });
        confirma.setNegativeButton("Não", new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialogInterface, int i)
            {
                texto.setText("Iniciando a aplicação");
                dialogInterface.dismiss();
                LoginActivity();
            }
        });
        confirma.create().show();
    }
    else
    {
        texto.setText("Iniciando a aplicação");
        LoginActivity();
    }
}

public void LoginActivity()
{
    Intent StartLoginActivity = new Intent(getApplicationContext(),LoginActivity.class);
    startActivity(StartLoginActivity);
    finish();
}


private static Integer getUrlContents(String theUrl) throws Exception
{
    Integer valor = 0;
    try
    {
        URL url = new URL(theUrl);
        URLConnection con = url.openConnection();
        BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf8"));
        valor = Integer.parseInt(reader.readLine());
        reader.close();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    return valor;
}

}

  • Hello. Welcome to Sopt. What is the content of the file located in that URL? What is the observed error? Clarify the problem better. Enjoy and make our [tour], if you have not done.

  • thanks for the help. yes I have already done the tour. the txt file only has 112 written. when the application is started on an android api 10 version 2.3.7 the program reads the 112 and gives true order to if but when started on latest android gives blank space and gives order Else. the program being the same do not understand why it does not work the same way in all versions. at night I can put a screen print of two emulators to see that it has different reactions.

No answers

Browser other questions tagged

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