如何通过code。打开手机图库 [英] How to open phones gallery through code

查看:79
本文介绍了如何通过code。打开手机图库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过一个按钮,点击打开手机的画廊。
在我的活动我有一个按钮,我想开通过按一下按钮画廊。

I wanna to open phones gallery through a button click.
In my activity I have a button, I want to open the gallery through that button click.

推荐答案

下面是一个示例code从应用程序开放的画廊。

Here is sample code for open gallery from app.

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);//
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_IMAGE);

OnActivityResult为获取图像。

OnActivityResult for get image.

public void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == SELECT_IMAGE) {
            if (resultCode == getActivity().RESULT_OK) {
                if (data != null) {
                    try {

                        Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), data.getData());

                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                } else if (resultCode == getActivity().RESULT_CANCELED) {
                    Toast.makeText(getActivity(), "Cancelled", Toast.LENGTH_SHORT).show();
                }
            }
        }
    }

这篇关于如何通过code。打开手机图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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