我想展示一个photoPicker,但只能使用特定格式的图片(png和jpeg)。
目前我有这个:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
它有效,但我在photoPicker中有所有图像格式。
我可以将setType()
更改为:setType("png, jpeg")
吗?
答案 0 :(得分:1)
我找到了解决方案:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/jpeg, image/png");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
我使用我可以在setType()中设置的MIME类型,如:
答案 1 :(得分:1)
试试这个
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/jpeg");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
或者您可以使用onActivityResult来检查文件:
filePath.endsWith(".jpeg")