android 2.2 中的 ContentResolver [问题]
我正在尝试在 Android 手机中插入 aduio 文件。相同的代码在 android 中也能正常工作 2.1
但是当我尝试在 Android 2.2 中使用它时;在 ContentResolver 中插入成功,但我
在图库中找不到我的音频文件(因此用户看不到它)
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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加“file:///”即可
Try adding "file:///" that will work