Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从uri ActivityNotFoundException打开Epub错误Android_Android_File Io_Uri_Activitynotfoundexception - Fatal编程技术网

从uri ActivityNotFoundException打开Epub错误Android

从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

当我按下按钮时,我会打开一个epub文件,但当我的android没有任何epub阅读器时,会显示一个祝酒词,说请安装epub阅读器,但我的代码不工作,然后停止我的应用程序,说应用程序意外停止

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说什么?哦!我没有意识到他在尝试之前就开始了活动,非常感谢你的帮助!我欠你一个人情!