如何在Android的默认图像查看器中打开图像

德米特里·博伊科

我使用以下代码打开默认文件管理器并找到图像,但是当我单击图像时,活动将关闭。

我可以在“活动”的顶部选择文件,Open但会看到单词,但是当我点击它时,它会自动关闭。

我想捕获此事件并在我的自定义活动中以全屏模式打开选定的图像。

int PICKFILE_REQUEST_CODE=10;
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(intent, PICKFILE_REQUEST_CODE);
德米特里·博伊科

终于,我开始工作了。

1.启动文件管理器以选择文件(在我的情况下是图像文件)

int PICKFILE_REQUEST_CODE=33; // class property

Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT); // It helps to get Image Uri 
intent.setType("image/*"); // Filter only images to open
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

2.使用onActivityResult事件获取带有PICKFILE_REQUEST_CODE的意图选择的结果

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == PICKFILE_REQUEST_CODE ) {
   if(resultCode == Activity.RESULT_OK){
      Uri imageUri = data.getData();     
      Intent intent = new Intent(this, ImageViewer.class);
      intent.putExtra("imageUri", imageUri.toString());
      startActivity(intent); // Start new intent to see the full sized image ImageViewer
    }
}

3.使用ImageViewer,我们可以使用Image进行所有工作

public class ImageViewer extends AppCompatActivity {

    private ImageView imgView;
    private String fullScreenInd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_viewer);

        Uri myUri = Uri.parse(getIntent().getExtras().getString("imageUri"));
        imgView = (ImageView)findViewById(R.id.fullImageView);
        imgView.setImageURI(myUri);

        imgView.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
        imgView.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
        imgView.setAdjustViewBounds(false);
        imgView.setScaleType(ImageView.ScaleType.FIT_XY);

    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Windows上使用Java在默认图像查看器中打开图像?

Python:在默认图像查看器中打开多个图像

如何通过提供文件路径在默认的图像查看器中打开图像?

无法使用照片的URI在Android的默认图像查看器中打开捕获的照片

Android在默认图库查看器中显示图像

如何从默认的图像查看器中裁剪?

使用默认的android图像查看器显示图片

如何编写一种在C#中打开图像的方法,该方法将使用移动设备上的默认图像查看器...?

更改默认图像查看器

如何在Windows®7图像查看器中删除该讨厌的颜色层?

如何通过默认图像查看器在Facebook上共享图像

如何在Android中通过Intent打开Pdf查看器

在Tumblr上启用默认的图像查看器

如何使图像页面查看器的图像迅速iOS

卸载图像查看器

用于多个图像的图像查看器

如何在媒体查看器中垂直设置样本图像缩略图栏?

如何在另一个活动中从uri设置导航抽屉查看器的图像

如何向下滑动图像并在数组中显示图像的URL?(本机图像查看器)

如何在反应原生网格图像查看器中传递动态获取的图像数组数据和反应原生中的标题

如何在php项目中集成iiif图像查看器?

如何获得支持 JPEG 2000 的图像查看器?

三.js:全景查看器中的图像波纹

使用查看器在不同的列表中显示相同的图像

图像查看器中的颜色不匹配

Android:如何使用底部的ListView制作图像查看器

如何在 Android 8.0 中查看带有默认图库的图像?

在使用图像查看器(GNOME的眼睛)的目录打开多个图像

如何在新标签页中打开由报表查看器生成的pdf?