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.
A Uri object is usually used to tell a ContentProvider what we want to access by reference. It is an immutable one-to-one mapping to a resource or data. The method Uri. parse creates a new Uri object from a properly formated String .
Immutable URI reference. A URI reference includes a URI and a fragment, the component of the URI following a '#'. Builds and parses URI references which conform to RFC 2396. In the interest of performance, this class performs little to no validation.
RoomDatabase provides direct access to the underlying database implementation but you should prefer using Dao classes. See also: Database.
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();
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With