从uri ActivityNotFoundException打开Epub错误Android
当我按下按钮时,我会打开一个epub文件,但当我的android没有任何epub阅读器时,会显示一个祝酒词,说请安装epub阅读器,但我的代码不工作,然后停止我的应用程序,说应用程序意外停止从uri ActivityNotFoundException打开Epub错误Android,android,file-io,uri,activitynotfoundexception,Android,File Io,Uri,Activitynotfoundexception,当我按下按钮时,我会打开一个epub文件,但当我的android没有任何epub阅读器时,会显示一个祝酒词,说请安装epub阅读器,但我的代码不工作,然后停止我的应用程序,说应用程序意外停止 Button leer = (Button) findViewById(R.id.Btnleer); leer.setOnClickListener(new OnClickListener() { @Override public void
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();
}
}
});
移除第一个
startActivity(intentradef)代码>紧跟在intentradef.setFlags之后的命令(Intent.FLAG\u ACTIVITY\u NO\u HISTORY)代码>。它在您的try catch
块之前被调用,因此引发异常。您需要一个打开ePub的应用程序logcat说什么?哦!我没有意识到他在尝试之前就开始了活动,非常感谢你的帮助!我欠你一个人情!