Android reads all Videos on the device, Kotlin

Android reads all Videos on the device, Kotlin

 

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

 

    private fun readAllVideo(context: Context): ArrayList<MyData> {
        val videos = ArrayList<MyData>()

        //读取手机图片
        val cursor = context.contentResolver.query(
            MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
            null,
            null,
            null,
            null
        )
        var index = 0
        while (cursor!!.moveToNext()) {
            //路径 uri
            val path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA))

            //名称
            val name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME))

            //大小
            val size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE))

            videos.add(MyData(path, index++))
        }
        cursor.close()

        return videos
    }

 

 

    class MyData(var path: String, val index: Int) {

    }

 

 

 

android 13 reads the name of all local pictures and stores the absolute path, Java_zhangphil's blog - CSDN blog[Set avatar on Android, take a picture with your phone or select a picture from the local album as an avatar] Social apps like WeChat, QQ, Weibo, etc. There is usually a function to set an avatar. There are usually two ways to set an avatar: 1. Let the user select an existing image in a picture library such as a local photo album and crop it as the avatar. Set an avatar on Android, take a photo with your phone or select a picture from the local album as an avatar_android avatar photo_zhangphil's blog-CSDN blog. Add text watermark to Android images and save the watermark text image to the specified file_zhangphil's blog-CSDN blog. https://blog.csdn.net/zhangphil/article/details/129639271

 

Guess you like

Origin blog.csdn.net/zhangphil/article/details/132173745