A Little Help Needed with a SQLite database to get a Ringtone Set

Discussion in 'Android App Developers' started by r2sjoblom, Dec 23, 2011.

  1. r2sjoblom

    r2sjoblom New Member

    Joined:
    Feb 24, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
    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:
    [SIZE=2] [LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] setDefaultRingtone() {[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// [/COLOR][/SIZE][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f9fbf][SIZE=2][COLOR=#7f9fbf]TODO[/B][/COLOR][/SIZE][/COLOR][/SIZE]
    [SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f] Auto-generated method stub[/LEFT][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//use the cursor from the [U]sql[/U] database and set the default [U]ringtone[/LEFT][/U][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]Random newrandom = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Random();[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dbCursor[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mydata[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getAllTitles();[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Cursorcount = [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dbCursor[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getCount();[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dbCursor[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] != [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) {[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] index = newrandom.nextInt(Cursorcount);[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dbCursor[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].moveToPosition(index);}[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] position2 = [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dbCursor[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getPosition();[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]long[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] l2 = [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dbCursor[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getLong([/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dbCursor[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getColumnIndexOrThrow([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"_id"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]));String str = [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dbCursor[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getString([/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dbCursor[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getColumnIndexOrThrow([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"title"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]));Uri localUri2 = ContentUris.[I]withAppendedId[/I](MediaStore.Audio.Media.[I]getContentUriForPath[/I](str), l2);[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//[U]Uri[/U] localUri = mRingtoneManager2.getRingtoneUri(dbCursor.getPosition());[/LEFT][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]Uri localUri = Uri.[I]parse[/I]([/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dbCursor[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getString([/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dbCursor[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getColumnIndexOrThrow([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"title"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])));Log.[I]i[/I]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Ringtones"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"music DB count: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + Cursorcount);Log.[I]i[/I]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Ringtones"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"cursor position: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + l2);Log.[I]i[/I]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Ringtones"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"music uri2: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + localUri2);Log.[I]i[/I]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Ringtones"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"music uri: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + localUri);[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//set default [U]ringtone[/LEFT][/U][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]try[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {RingtoneManager.[I]setActualDefaultRingtoneUri[/I](getRandom.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], position2, localUri2);} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]catch[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (Exception localException) { Log.[I]i[/I]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Ringtones"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"ERROR: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Setting Ringtone"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); }[/LEFT]}
    [/SIZE]

     
  2. r2sjoblom

    r2sjoblom New Member

    Joined:
    Feb 24, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
    Got it working, just needed to change my listarray from MediaStore to my original RingtoneManager

    Code:
    [SIZE=2] [LEFT]String[] from = {[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mCursor2[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getColumnName([/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mRingtoneManager2[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[/SIZE][I][U][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TITLE_COLUMN_INDEX[/I][/U][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]), [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mCursor2[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getColumnName([/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mRingtoneManager2[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[/SIZE][I][U][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]URI_COLUMN_INDEX[/I][/U][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])}; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// get the list items for the [U]listadapter[/U] could be TITLE or URI[/LEFT][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE]
     
Search tags for this page

ringtone database android

,

sql select random column