ContentResolver.insert 返回 null

发布于 2024-10-06 04:39:27 字数 762 浏览 0 评论 0原文

我有时在将声音设置为活动内部的铃声/通知时遇到问题:

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 类似于“content://media/external/audio/media/23”,但有时它为空。 我不知道问题出在哪里,音频文件没问题(它们播放正常),显然插入方法不会抛出任何异常。 我查看了文档,但没有任何关于返回 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);

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只是我以为 2024-10-13 04:39:27

内容提供商尚不支持远程异常。当您返回 null Uri 时,我会查看 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.

薔薇婲 2024-10-13 04:39:27

23 ,24 应该是媒体的音量调高和调低。 uri 应该是相同的。

23 ,24 should be the volume up and down for the media. uri should be the same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文