Good evening. Although I can not figure out what the error is, I can not 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 fine. why?
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;
}
}