【问题标题】:Can't copy file to the public storage无法将文件复制到公共存储
【发布时间】:2015-04-17 20:06:18
【问题描述】:

我正在尝试启动一个意图以打开一个图像文件,我从互联网下载。

我可以将图像文件下载到应用程序的内部存储中,但我无法将其复制到我的 Android 设备上的公共 /Documents 目录中,以启动 Intent。

这就是我复制文件的方式

var bytes = System.IO.File.ReadAllBytes (privatePath);
Java.IO.File docFolder = new Java.IO.File (global::Android.OS.Environment.ExternalStorageDirectory + "/MyAppCache");
if (!docFolder.Exists ()) docFolder.Mkdir ();

Java.IO.File file = new Java.IO.File (docFolder.AbsolutePath, "cache.jpg");
file.CreateNewFile();

Java.IO.FileOutputStream fOut = new Java.IO.FileOutputStream (file);
fOut.Write (bytes);
fOut.Close ();

return file.AbsolutePath;

我使用的返回路径

global::Android.Net.Uri uri = global::Android.Net.Uri.Parse(FilePublisher.CopyToPublic());
StartActivity (new Intent (Intent.ActionView, uri));

我得到的结果是

No Activity found to handle Intent { act=android.intent.action.VIEW dat=/storage/emulated/0/MyAppCache/cache.jpg }

我检查了我设备上的 /storage 文件夹,其中甚至没有 MyAppCache 文件夹。

这里有什么问题?

【问题讨论】:

    标签: c# android android-intent xamarin


    【解决方案1】:

    您在 Intent 中传递的 URI 不包含该方案。您可以从错误中看到这一点:

    No Activity found to handle Intent { act=android.intent.action.VIEW dat=/storage/emulated/0/MyAppCache/cache.jpg }
    

    "dat=" 需要以file:/// 开头。

    【讨论】:

      猜你喜欢
      • 2021-03-09
      • 1970-01-01
      • 2016-10-18
      • 2016-07-02
      • 2019-10-13
      • 2020-02-27
      • 2018-10-29
      • 1970-01-01
      • 2020-01-21
      相关资源
      最近更新 更多