【问题标题】:Open Epub from uri ActivityNotFoundException Error Android从 uri ActivityNotFoundException 错误 Android 打开 Epub
【发布时间】:2013-05-17 18:17:21
【问题描述】:

当我按下按钮时我打开了一个 epub 文件,但是当我的 android 没有任何 epub 阅读器时,显示一个 toast 说请安装 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();

} 
            }

            });

【问题讨论】:

  • 你需要一个打开epub的应用程序
  • logcat 说什么?

标签: android file-io uri activitynotfoundexception


【解决方案1】:

删除intentreadf.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 之后的第一个startActivity(intentreadf); 命令。它在您的 try-catch 块之前被调用,因此会引发异常。

【讨论】:

  • 哦!在尝试之前我没有意识到他正在开始活动,非常感谢您的帮助!我欠你一个!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-08
  • 1970-01-01
  • 2022-01-06
  • 1970-01-01
  • 2015-10-16
  • 2019-04-14
  • 1970-01-01
相关资源
最近更新 更多