本文介绍了选择海报的图像从 - 机器人,如何让尤里斯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的描述:的

如果呼叫者可以处理多个归还物品的话,就可以指定EXTRA_ALLOW_MULTIPLE(执行多个选择用户),以表明这一点。

这是pretty有趣。在这里,他们被它指的是用例,其中用户可以选择多个项目?

  @TargetApi(Build.VERSION_ codeS.JELLY_BEAN_MR2)
    公共无效selectPhotos(){
        意向意图=新的Intent();
        intent.setType(图像/ *);
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,真);
        startActivityForResult(Intent.createChooser(意向,
                选择多张图像),SELECT_PHOTOS_RESULT);
    }
保护无效的onActivityResult(INT申请code,INT结果code,意图意图){        super.onActivityResult(要求code,结果code,意向);        如果(结果code == RESULT_OK){            开关(要求code){
                案例SELECT_PHOTOS_RESULT:
                    //如何获得这些URI?
                    ...
                    打破;        }    }


解决方案

也许,我是有点晚了回答这个问题。可以帮助别人谁是寻找一个答案。

 如果(意向!= NULL){
                ClipData clipData = intent.getClipData();
                如果(clipData!= NULL){
                    的for(int i = 0; I< clipData.getItemCount();我++){
                        ClipData.Item项= clipData.getItemAt(ⅰ);
                        URI URI = item.getUri();                        //如果你需要的图像的绝对路径
                        字符串路径= getRealPathFromURI(getActivity(),URI)
                    }
                }
            }公共字符串getRealPathFromURI(上下文的背景下,乌里contentUri){
    光标光标= NULL;
    尝试{
        的String [] = PROJ {MediaStore.Images.Media.DATA};
        光标= context.getContentResolver()查询(contentUri,凸出,空,
                NULL,NULL);
        INT与Column_Index =光标
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        返回cursor.getString(Column_Index中);
    } {最后
        如果(指针!= NULL){
            cursor.close();
        }
    }
}

the describe: http://www.rqgg.net/topic/vrvkz-select-multiple-images-from-android-gallery.html

If the caller can handle multiple returned items (the user performing multiple selection), then it can specify EXTRA_ALLOW_MULTIPLE to indicate this.

This is pretty interesting. Here they are referring it to the use case where a user can select multiple items?

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
    public void selectPhotos(){
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        startActivityForResult(Intent.createChooser(intent,
                "select multiple images"), SELECT_PHOTOS_RESULT);
    }


protected void onActivityResult(int requestCode, int resultCode, Intent intent) {

        super.onActivityResult(requestCode, resultCode, intent);

        if (resultCode == RESULT_OK) {

            switch (requestCode) {
                case SELECT_PHOTOS_RESULT:
                    //how to get the Uris?
                    ...
                    break;

        }

    }
解决方案

Probably, i am little late to answer this. Might help someone who is looking for an answer to this.

    if (intent != null) {
                ClipData clipData = intent.getClipData();
                if (clipData != null) {
                    for (int i = 0; i < clipData.getItemCount(); i++) {
                        ClipData.Item item = clipData.getItemAt(i);
                        Uri uri = item.getUri();

                        //In case you need image's absolute path
                        String path= getRealPathFromURI(getActivity(), uri)
                    }
                }
            }

public String getRealPathFromURI(Context context, Uri contentUri) {
    Cursor cursor = null;
    try {
        String[] proj = { MediaStore.Images.Media.DATA };
        cursor = context.getContentResolver().query(contentUri, proj, null,
                null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

这篇关于选择海报的图像从 - 机器人,如何让尤里斯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 00:33