Android: Let user pick image or video from Gallery

后端 未结 8 614
死守一世寂寞
死守一世寂寞 2021-01-30 20:44

Is it possible to to start Gallery in such a way so both pictures and videos are shown?

Thanks

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 21:25

    (EDIT: I don't use it anymore, we went back to the two choices "pick image" and "pick video". The problem was with some Sony phone. So, it's not 100% solution below, be careful! )

    This is what I use:

    if (Build.VERSION.SDK_INT < 19) {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/* video/*");
        startActivityForResult(Intent.createChooser(intent, getResources().getString(R.string.select_picture)), SELECT_GALLERY);
    } else {
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"image/*", "video/*"});
        startActivityForResult(intent, SELECT_GALLERY_KITKAT);
    }
    

    The key here is intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"image/*", "video/*"});

提交回复
热议问题