ContentResolver in android 2.2 [issue]

筅森魡賤 提交于 2019-12-13 05:40:57

问题


Am trying to insert an aduio file in the android phone. the same code works fin in android 2.1

but when i try to use it in Android 2.2; the inserting in ContentResolver succseed but i can't

find my audio file in the gallery (so the user can't see it)


context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename)));  

File k = new File(path, filename);  

ContentValues values = new ContentValues();  
values.put(MediaStore.Audio.Media.DATA, k.getAbsolutePath());  
values.put(MediaStore.Audio.Media.TITLE, aud.TITLE);  
values.put(MediaStore.Audio.Media.MIME_TYPE, aud.MIME_TYPE);  
values.put(MediaStore.Audio.Media.ARTIST,  aud.ARTIST);  
values.put(MediaStore.Audio.Media.IS_RINGTONE, aud.IS_RINGTONE);  
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, aud.IS_NOTIFICATION);  
values.put(MediaStore.Audio.Media.IS_ALARM, aud.IS_ALARM);  
values.put(MediaStore.Audio.Media.IS_MUSIC, aud.IS_MUSIC);  

//Insert it into the database  
context.getContentResolver().insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values); 

回答1:


Try adding "file:///" that will work



来源:https://stackoverflow.com/questions/6108243/contentresolver-in-android-2-2-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!