安卓:URI开放的用行动显示图像 [英] Android : URI for open an image with ACTION View

查看:96
本文介绍了安卓:URI开放的用行动显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在code

protected static final String DIR_IMAGE = "/data/data/it.android.myprogram/images/";
Intent intent = new Intent(); 
intent.setAction(android.content.Intent.ACTION_VIEW); 
Uri u = Uri.fromFile(destinationFile);
intent.setDataAndType(u, "image/*");
startActivity(intent); 

要打开该文件是为/data/data/it.android.myprogram/images如果我这样做:

the file to open is into /data/data/it.android.myprogram/images if I do :

File dir = new File(DIR_IMAGE);
String[] files = dir.list();

var这个文件中包含的所有文件,但是当我开始

The var files contain all files but when I start

intent.setDataAndType(u, "image/*");
startActivity(intent); 

据dispaly消息不可能找到/data/data/it.android.myprogram/images/img1.jpg

It dispaly the message Impossible to find /data/data/it.android.myprogram/images/img1.jpg

为什么?

推荐答案

文件只能由您的应用程序访问。如果你想通过他们的意图发送给其他人的应用程序,你必须使用你的活动 openFileOutput 方法复制的内容。

Files in /data/data/it.android.myprogram are only accessible by your application. If you want to send them via Intent to others applications, you must copy content in using openFileOutput method of your activity.

protected static final String DIR_IMAGE = "/data/data/it.android.myprogram/images/";
String filePath = DIR_IMAGE + "fileName";
FileInputStream fileInputStream = new FileInputStream(new File(filePath));
FileOutputStream fileOutputStream = openFileOutput("fileName", Activity.MODE_WORLD_READABLE);
ByteStreams.copy(fileInputStream, fileOutputStream);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("content://it.android.myprogram/fileName"), "image/*");

希望它可以帮助

Hope it helps

这篇关于安卓:URI开放的用行动显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆