LoginSignup
5
4

More than 5 years have passed since last update.

Android URIからMimeTypeを取得する

Last updated at Posted at 2018-09-11

こんな関数を作成すればMimeTypeを取得できます。
拡張子から判別とか怪しい気もするので。。

private fun getMimeType(context: Context, uri: Uri): String? {
    val cursor = context.contentResolver.query(uri, arrayOf(MediaStore.MediaColumns.MIME_TYPE), null, null, null)
    return cursor.use {
        if (cursor.moveToNext()) {
            return@use cursor.getString(0)
        } else {
            return@use null
        }
    }
}

参考
https://stackoverflow.com/questions/9414487/how-to-get-the-image-format-of-the-images-from-gallery

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4