简体   繁体   English

ContentResolver 插入 MediaStore.Audio.Media.EXTERNAL_CONTENT_URI 错误

[英]ContentResolver insert MediaStore.Audio.Media.EXTERNAL_CONTENT_URI error

I want to get a uri by contentResolver insert a music.我想通过 contentResolver 插入音乐来获取 uri。

val contentValues = ContentValues()
contentValues.put(MediaStore.Audio.Media.DISPLAY_NAME, music.displayName)
contentResolver.insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, contentValues)

if not set MediaStore.Audio.Media.DATA, must be error.如果没有设置 MediaStore.Audio.Media.DATA,一定是错误的。

if use same method insert to MediaStore.Images.Media.EXTERNAL_CONTENT_URI or MediaStore.Video.Media.EXTERNAL_CONTENT_URI is successful.如果使用相同的方法插入 MediaStore.Images.Media.EXTERNAL_CONTENT_URI 或 MediaStore.Video.Media.EXTERNAL_CONTENT_URI 是成功的。

I'm only want to get a uri for wirte data at Android Q.我只想在 Android Q 获得一个用于写入数据的 uri。

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.lastIndexOf(int)' on a null object reference
   at android.os.Parcel.createException(Parcel.java:1959)
   at android.os.Parcel.readException(Parcel.java:1921)
   at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
   at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
   at android.content.ContentProviderProxy.insert(ContentProviderNative.java:476)
   at android.content.ContentResolver.insert(ContentResolver.java:1603)

For android Q and newer, you should set MediaStore.Audio.Media.RELATIVE_PATH instead of MediaStore.Audio.Media.DATA对于 android Q 和更新版本,您应该设置MediaStore.Audio.Media.RELATIVE_PATH而不是MediaStore.Audio.Media.DATA

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    contentValues.put(MediaStore.Audio.Media.RELATIVE_PATH, "${Environment.DIRECTORY_MUSIC}")
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MediaStore.Audio.Media.EXTERNAL_CONTENT_URI报告为未知URI - MediaStore.Audio.Media.EXTERNAL_CONTENT_URI reported as Unknown URI MediaStore.Audio.Media.EXTERNAL_CONTENT_URI返回一个空游标 - MediaStore.Audio.Media.EXTERNAL_CONTENT_URI return an empty cursor 在查询`MediaStore.Audio.Media.EXTERNAL_CONTENT_URI`之前,有没有办法强制系统媒体重新扫描? - Is there any way to force a system media rescan before querying `MediaStore.Audio.Media.EXTERNAL_CONTENT_URI`? 在Android中的MediaStore.Audio.Media.EXTERNAL_CONTENT_URI中插入音频文件时出现问题 - problem while inserting audio file in MediaStore.Audio.Media.EXTERNAL_CONTENT_URI in android api 29+ 已弃用 MediaStore.Audio.Media.EXTERNAL_CONTENT_URI? - MediaStore.Audio.Media.EXTERNAL_CONTENT_URI is deprecated for api 29+? MediaStore.Audio.Media.EXTERNAL_CONTENT_URI不扫描数据文件夹内部 - MediaStore.Audio.Media.EXTERNAL_CONTENT_URI does not scan inside data folder 我的设备上的查询问题(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,null,null,null,null) - problem with query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null) on my device 使用PICK_ACTION和MediaStore.Audio.Media.EXTERNAL_CONTENT_URI时是否可以过滤或删除显示的结果? - Is it possible to filter or remove results shown when using PICK_ACTION and MediaStore.Audio.Media.EXTERNAL_CONTENT_URI? Android 9 (Pie) ContentResolver 查询 MediaStore.Images.Media.EXTERNAL_CONTENT_URI 在 api 28 上返回 null - Android 9 (Pie) ContentResolver query MediaStore.Images.Media.EXTERNAL_CONTENT_URI returns null on api 28 未为类型MediaStore.Audio.Media android定义方法Media.getBitmap(ContentResolver,Uri) - method Media.getBitmap(ContentResolver, Uri) is undefined for type MediaStore.Audio.Media android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM