从android picker-intent中选择位图

olqngx59  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(221)

我试图挑选位图(.bmp)文件使用android picker,我使用mimetype为这个。但是位图文件是灰色的,我不能选择它们。我尝试使用不同的扩展来设置intent中的类型,比如“image/bmp”、“image/com.microsoft.bmp”、“image/bitmap”,但没有成功。
一种方法是使用“image/*”,但它也允许其他不允许的文件
我的代码:

chooseFile.type = ALLOWED_MIME_TYPES
chooseFile.addCategory(Intent.CATEGORY_OPENABLE)
chooseFile.putExtra(Intent.EXTRA_MIME_TYPES, availableMimeTypes)
chooseFile = Intent.createChooser(chooseFile, "Pick file")
startActivityForResult(chooseFile, PICKFILE_RESULT_CODE)

* Mime types class*

const val docMimeType = "application/msword"
const val docxMimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
const val txtMimeType = "text/plain"
const val odtMimeType = "application/vnd.oasis.opendocument.text"
const val pdfMimeType = "application/pdf"
const val jpgMimeType = "image/jpg"
const val jpegMimeType = "image/jpeg"
const val bmpMimeType = "image/bmp"
const val bmpMimeType2 = "image/com.microsoft.bmp"
const val pngMimeType = "image/png"
const val heicMimeType = "image/heic"

const val ALLOWED_MIME_TYPES = "application/msword|application/vnd.openxmlformats-officedocument.wordprocessingml.document|" +
        "image/bmp|image/com.microsoft.bmp|text/plain|application/vnd.oasis.opendocument.text|application/pdf|image/jpg|image/jpeg|image/heic"

val availableMimeTypes = arrayOf(
        docMimeType,
        docxMimeType,
        txtMimeType,
        odtMimeType,
        pdfMimeType,
        jpgMimeType,
        jpegMimeType,
        bmpMimeType,
        bmpMimeType2,
        pngMimeType,
        heicMimeType
)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题