Basically what I want to be able to do is set a Default Ringtone from this particular activity. The idea of my APK I am doing is a simple random ringtone sleector for the user. They will put a check mark next to the ringtones they want, which will populate a SQLite database then (this is my issue) randomly select a ringtone from the list in the SQL database. This is all fairly simple but I am just stuck on this next (last) part. Below is the code. I am trying two different ways to get it to work with different uri's, that is why I have two at the bottom. The Log.i's show the proper information. The proper database count, selecting a random number from the "_id" column, and finially selecting the actual uri from the "title" column. The problem is that the RingtoneManager.setActualDefaultRingtoneUri() is not working. I have used this method numberous times before but this is just a nightmare. Any help would be great. Thanks in advanced.
Code:
privatevoid setDefaultRingtone() {// TODO
Auto-generated method stub
//use the cursor from the sql database and set the default ringtone
Random newrandom =
new Random();dbCursor = mydata.getAllTitles();int Cursorcount = dbCursor.getCount();if (dbCursor != null) {int index = newrandom.nextInt(Cursorcount);dbCursor.moveToPosition(index);}int position2 = dbCursor.getPosition();long l2 = dbCursor.getLong(dbCursor.getColumnIndexOrThrow("_id"));String str = dbCursor.getString(dbCursor.getColumnIndexOrThrow("title"));Uri localUri2 = ContentUris.withAppendedId(MediaStore.Audio.Media.getContentUriForPath(str), l2);//Uri localUri = mRingtoneManager2.getRingtoneUri(dbCursor.getPosition());
Uri localUri = Uri.parse(
dbCursor.getString(dbCursor.getColumnIndexOrThrow("title")));Log.i("Ringtones", "music DB count: " + Cursorcount);Log.i("Ringtones", "cursor position: " + l2);Log.i("Ringtones", "music uri2: " + localUri2);Log.i("Ringtones", "music uri: " + localUri);//set default ringtone
try {RingtoneManager.setActualDefaultRingtoneUri(getRandom.this, position2, localUri2);} catch (Exception localException) { Log.i("Ringtones", "ERROR: " + "Setting Ringtone"); }
}