安卓:保存android.net.Uri对象数据库 [英] Android: Save android.net.Uri object to Database
问题描述
我想要做的就是从用户选择的铃声,设置AlarmManager报警时闹钟响起来播放铃声。但我需要保存铃声在数据库中,所以我可以手机重启后所有报警复位。
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?
我试过如下:
1)保存在数据库铃声标题,然后检索它并将其附加到一个默认铃声路径。但问题是,铃声可能会从不同的位置加载
2)存储URI方案,方案spefici部分和碎片,然后调用Uri.fromParts创建URI。
3)创建一个InputStream,字节[]从乌里阵列并将其保存为一个blob,然后回读,并把结果以乌里
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
没有这些作品。
您的帮助是多少AP preciated。
Your help is much appreciated.
推荐答案
存放URI在数据库中的字符串,然后再加载它。
Store the URI as a string in the database and then load it later.
// This will get the uri in a string format
String s = mUri.toString();
当你从数据库中检索该字符串,重建URI是这样的:
When you retrieve the string from the database, rebuild the URI like this:
// This will decode the string into a URI
Uri mUri = Uri.parse(s);
希望有所帮助。祝你好运!
Hope that helps. Good luck!
这篇关于安卓:保存android.net.Uri对象数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!