Commit 41d9bd85 authored by wanglei's avatar wanglei

...提交部分ui...

parent 8ad6118d
package com.base.superpdfreader.helps
import android.annotation.SuppressLint
import android.content.Context
import android.database.Cursor
import android.media.MediaScannerConnection
import android.net.Uri
import android.os.Environment
import android.provider.MediaStore
import com.base.superpdfreader.bean.DocumentBean
object MediaStoreHelp {
@SuppressLint("Range")
fun Context.geFileMedia(list: ArrayList<DocumentBean>, selectionArgs: Array<String>): ArrayList<DocumentBean> {
val projection = arrayOf(
MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DATA,
MediaStore.Files.FileColumns.MIME_TYPE,
MediaStore.Files.FileColumns.TITLE,
MediaStore.Files.FileColumns.SIZE,
)
// 选择条件,筛选出MIME类型为application/zip的文件
val selection = MediaStore.Files.FileColumns.MIME_TYPE + "=?"
// val selectionArgs = arrayOf("application/zip")
var cursor: Cursor? = null
try {
cursor = contentResolver.query(
MediaStore.Files.getContentUri("external"), // 你也可以使用INTERNAL_CONTENT_URI来查询内部存储
projection,
selection,
selectionArgs,
null // 无排序
)
if (cursor != null) {
while (cursor.moveToNext()) {
val tittle = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.TITLE))
val path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA))
val size = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.SIZE)).toLong()
// 其他属性...
}
cursor.close()
}
} catch (e: Exception) {
} finally {
cursor?.close()
}
return list
}
val commonMediaDir = arrayOf(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).absolutePath,
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath,
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).absolutePath,
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).absolutePath,
)
fun Context.updateMediaStore(
filePath: Array<String> = commonMediaDir
) {
MediaScannerConnection.scanFile(
this, filePath, null
) { path: String?, uri: Uri? -> }
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment