Remove the first startActivity(intentreadf);
command right after intentreadf.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
. It gets called before your try-catch
block, and hence throws an exception.
Open Epub from uri ActivityNotFoundException Error Android
-
29-05-2022 - |
Question
Im open a epub file when I press a button, but when my android don´t have any epub reader, show an toast saying please install epub reader, but my code not works, and stopp my app saying the app stop unexpectedly.
Button leer = (Button) findViewById(R.id.Btnleer);
leer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v2) {
// TODO Auto-generated method stub
File file = new File("/sdcard/Mi Biblioteca/"+nomb+".epub");
Intent intentreadf = new Intent(Intent.ACTION_VIEW);
intentreadf.setDataAndType(Uri.fromFile(file),"application/epub+zip");
intentreadf.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intentreadf);
try {
startActivity(intentreadf);
}
catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(),
"favor descargar lector epub.",
Toast.LENGTH_SHORT).show();
}
}
});
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow