【问题标题】:Intent URI transfer problemsIntent URI 传输问题
【发布时间】:2012-03-31 08:00:08
【问题描述】:

我无法让 adobe reader 应用程序在我的 sdcard 中打开 pdf... 这是我目前正在尝试的。

Intent intent = new Intent(Intent.ACTION_VIEW);
String aux = Environment.getExternalStorageDirectory() + "/mhtemp/jazz.pdf";
intent.setDataAndType(Uri.parse(aux), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
    startActivity(intent);
    } 
catch (ActivityNotFoundException e) { continues....

当我继续执行此操作时,我会收到来自 adobe reader 的通知,内容为“无法打开文件”。尽管如此,我还是使用文件查看器进行了检查,并且该文件确实存在于我创建的文件夹中。最重要的是,如果我尝试从文件查看器中打开它,它可以工作!我不知道我在这里的意图做错了什么......

【问题讨论】:

    标签: android android-intent path uri


    【解决方案1】:

    尝试将您的文件路径正确转换为 Uri,如下所示:

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "/mhtemp/jazz.pdf"));
    intent.setDataAndType(uri, "application/pdf");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    try {
        startActivity(intent);
        } 
    catch (ActivityNotFoundException e) { continues....
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多