Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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
Android 发射后图像意图关闭_Android_Android Intent_Download_Xamarin - Fatal编程技术网

Android 发射后图像意图关闭

Android 发射后图像意图关闭,android,android-intent,download,xamarin,Android,Android Intent,Download,Xamarin,我下载一个图像,将其复制到一个公共文件夹,并尝试以图像的意图打开它 但当我启动intent时,我的应用程序尝试打开另一个窗口,该窗口立即关闭并返回到应用程序 为什么会这样 public Intent CopyToPublic(string privatePath) { string extBasePath = global::Android.OS.Environment.ExternalStorageDirectory.Path; string upperFolder = "My

我下载一个图像,将其复制到一个公共文件夹,并尝试以图像的意图打开它

但当我启动intent时,我的应用程序尝试打开另一个窗口,该窗口立即关闭并返回到应用程序

为什么会这样

public Intent CopyToPublic(string privatePath)
{
    string extBasePath = global::Android.OS.Environment.ExternalStorageDirectory.Path;
    string upperFolder = "MyApp";
    var bytes = System.IO.File.ReadAllBytes (privatePath);

    Java.IO.File f = new Java.IO.File (extBasePath + "/" + upperFolder);
    if (!f.Exists()) f.Mkdir ();

    var extPath = String.Format ("{0}/{1}/{2}", extBasePath, upperFolder, "cache.jpg");
    System.IO.File.WriteAllBytes (extPath, bytes);

    global::Android.Net.Uri uri = global::Android.Net.Uri.Parse (extPath);

    Intent intent = new Intent (Intent.ActionView);
    intent.SetDataAndType (uri, "image/*");

    return intent;
}

//Open
StartActivity (FilePublisher.Static.CopyToPublic(path));

本例中的extPath是/storage/emulated/0/Miraclix/cache.jpg,当我用文件浏览器检查它时,它就存在了。

@Stan,是的。它是Xamarin.cache.jpg。好啊0字节?从资源管理器中使用图像查看器是否可见?服务器上的文件大小?@greenapps cache.jpg有48 Kb。但有趣的是,当我选择FileExplorer打开意图时,图像无法加载。这一点都不有趣。将cache.jpg与服务器上的进行比较。六羟甲基三聚氰胺六甲醚。。。我不太明白你在做什么。您应该使用文件浏览器浏览到.jpg,然后让文件浏览器打开图像的查看器。我可以从文件浏览器应用程序打开复制的图像。我无法从意图中打开图像。