[英]How to set up intent for viewing image that is saved in internal storage with default Android viewer?
What I am trying to do is to download image from web (its in GIF format, if that changes anything) and show it on screen with zoom/pan capability.我要做的是从 web 下载图像(如果有任何改变,它是 GIF 格式),并在屏幕上显示具有缩放/平移功能。 I've successfully downloaded image into Bitmap instance myBitmap , but ImageView doesnt have zooming feature.
我已成功将图像下载到 Bitmap 实例myBitmap ,但 ImageView 没有缩放功能。 So instead I'm willing to present it with default viewer which has zoom/pan features.
因此,我愿意使用具有缩放/平移功能的默认查看器来展示它。 In order to set up intent I need to provide URI to saved file.
为了设置意图,我需要提供保存文件的 URI。 So first I save file into internal storage (also giving access to other apps withe MODE_WORLD_READABLE):
所以首先我将文件保存到内部存储中(也可以通过 MODE_WORLD_READABLE 访问其他应用程序):
try {
FileOutputStream out = openFileOutput("scrible",
Context.MODE_WORLD_READABLE);
myBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (FileNotFoundException e) {
Log.d(myTag, e.toString());
}
Then I successfully check its really readable:然后我成功地检查了它的可读性:
File myFile = new File(getFilesDir(), "scrible");
if (myFile.canRead()) {
Log.d(myTag, "Its readable");
}
Then I try to set up intent (which gives me error: stopped unexpectedly):然后我尝试设置意图(这给了我错误:意外停止):
Uri fileUri = Uri.fromFile(myFile);
startActivity(new Intent(Intent.ACTION_VIEW, fileUri));
I've tried to set up intent separately and it doesnt give error antil call to startActivity(intent);我尝试单独设置意图,但它没有给startActivity(intent) 的错误调用提供错误提示;
What I am doing wrong?我做错了什么?
The following works well for me:以下对我很有效:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(outputFileName)),"image/jpeg");
startActivity(intent);
The difference that I see is that you do not call the setDataAndType
.我看到的区别是您不调用
setDataAndType
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.