ContentResolver.insert返回null [英] ContentResolver.insert returns null

查看:2668
本文介绍了ContentResolver.insert返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置的声音从一个活动里面的铃声/通知时,有时会遇到问题

I sometimes have a problem when setting sounds as ringtones / notifications from inside an activity:

ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, source);
values.put(MediaStore.MediaColumns.TITLE, "abc");
values.put(MediaStore.MediaColumns.SIZE, new File(source).length());
values.put(MediaStore.MediaColumns.MIME_TYPE, mime);
values.put(MediaStore.Audio.Media.ARTIST, "xyz");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);

final Uri curi = MediaStore.Audio.Media.getContentUriForPath(source);
Uri uri = getContentResolver().insert(curi, values);

大部分时间URI是一样的东西的内容://媒体/外部/音频/媒体/ 23,但有时为空。
我不知道问题出在哪里,音频文件都ok(他们玩OK),显然插入方法不抛出任何异常。
我通过文档看了,但并没有什么关于返回null方法。
可能是什么问题?

most time uri is something like "content://media/external/audio/media/23", but sometimes it is null. I don't know where the problem lies, the audio files are ok (they play ok) and obviously the insert method does not throw any exception. I looked through the documentation but there is nothing about the method returning null. What could be the problem?

推荐答案

内容供应商不支持远程异常呢。我想看看在logcat中,当你返回乌里空。我怀疑媒体提供商将抛出某种异常。

Content providers don't support remote exceptions yet. I would look in logcat when you get the null Uri being returned. I suspect the media provider will be throwing some sort of exception.

这篇关于ContentResolver.insert返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆