简体   繁体   English

如何设置使用默认 Android 查看器查看保存在内部存储中的图像的意图?

[英]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.

相关问题 如何设置使用默认 Android 图像查看器查看 Bitmap 的意图? - How to set up intent for viewing Bitmap with default Android image viewer? 使用getExternalStoragePublicDirectory保存的Android映像不会显示在内部存储中 - Android image saved using getExternalStoragePublicDirectory wont show up in internal storage 如何将图像按钮设置为我的内部存储(Android)中的某些图像? - How to set Image Button to some image in my internal storage (Android)? 默认情况下,如何在ActionOpenDocument intent中显示“内部存储”选项 - How to show the “internal storage” option in an ActionOpenDocument intent by default 在内部存储中找不到保存到文本文件的数据,如何将文件保存在内部存储 android studio 中? - Cant find the saved data to text file in internal storage, How to save file in internal storage android studio? 如何使用Intent.ACTION_VIEW打开保存到内部存储的私有文件? - How to open private files saved to the internal storage using Intent.ACTION_VIEW? 如何将位图图像保存到Android内部存储? - How to save a bitmap image to the Android internal Storage? Android,如何在内部存储中存储图像? - Android, How to store image in internal storage? 我在哪里可以在Android的内部存储中存储默认图像 - Where can i store default Image on internal storage in android 您将默认图像存储在android内部存储中的什么位置? - where do you store a default image on internal storage of android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM