Android:将 android.net.Uri 对象保存到数据库
我想做的是从用户那里获取选定的铃声,设置 AlarmManager 闹钟以在闹钟关闭时播放该铃声。但我需要将铃声保存在数据库中,以便在手机重启后重置所有警报。
我的问题是将铃声 Uri 保存到数据库以便稍后检索的最佳方法是什么?
我尝试了以下操作:
1)将铃声标题保存在数据库中,然后检索它并将其附加到默认铃声路径。但问题是铃声可能是从不同的位置加载的 2) 存储uri方案、方案特定部分和片段,然后调用Uri.fromParts创建Uri。 3)从 Uri 创建一个 inputStream、byte[] 数组并将其保存为 blob,然后读回并将结果转换为 Uri
这些都不起作用。
非常感谢您的帮助。
What i m trying to do is get the selected ringtone from the user, set an AlarmManager alarm to play that ringtone when the alarm goes Off. but I need to save the ringtone in the database so I can reset all the alarms after phone reboot.
my question is what is the best way to save the ringtone Uri to the database to retrieve later?
I tried the followings:
1) save the ringtone title in the DB and then retrieve it and append it to a default ringtone path. but the issue, is that the ringtone might be loaded from a different location
2) Storing the uri scheme, scheme spefici part and fragment and then call Uri.fromParts to create the Uri.
3) create an inputStream, byte[] array from the Uri and saving it as a blob and then reading it back and cast the result to Uri
none of these works.
Your help is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 URI 作为字符串存储在数据库中,然后再加载。
当您从数据库检索字符串时,请像这样重建 URI:
希望有帮助。祝你好运!
Store the URI as a string in the database and then load it later.
When you retrieve the string from the database, rebuild the URI like this:
Hope that helps. Good luck!