2

Hi guys I want to set the device ring-tone programmatically but the application crashes.

The code I used is this:

@Override
public void onClick(View v) {

    Uri uri = Uri.parse("android.resource://"
      +"com.ghzncl.barneystinsonsoundboard/"+R.raw.single]);

    RingtoneManager.setActualDefaultRingtoneUri(
      mContext, RingtoneManager.TYPE_NOTIFICATION, uri
    );

    // I set the data source of the mPlayer. I pass to 
    // the method the context and the uri of the resource.
    try{
        // I reset the mPlayer to its uninitialized state, in
        // this way I don't need to stop the previews running quotes. 
        mPlayer.reset();
        mPlayer.setDataSource(mContext,uri);
    }catch(Exception e){
        // Do Exception handling here...
    }

    try{
        mPlayer.prepare();
    }catch(Exception e){
        // Do Exception handling here...
    }

    //The quotes start
    mPlayer.start();
}

Anyone can please help me??

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
Nicola
  • 21
  • 1
  • 2
  • check this http://stackoverflow.com/questions/1986756/setting-ringtone-in-android – Randroid Aug 24 '11 at 06:05
  • Now is difference I added the permission and the application doesn't crash anymore but the ringtone is set to the default android ringtone and not to the my ringtone. Why? – Nicola Aug 24 '11 at 10:23
  • @Nicola i am having the same problem how did you solve it – Tuhin Bhatt Nov 11 '12 at 16:30

1 Answers1

0

Nocola i used this code in order to set as ringtone:

ContentValues values = new ContentValues(4);
long current = System.currentTimeMillis();
values.put(MediaStore.MediaColumns.DATA, path+audioname );
values.put(MediaStore.MediaColumns.TITLE,  path+audioname );
values.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/3gpp");
 //new
values.put(MediaStore.Audio.Media.ARTIST, "cssounds ");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
values.put(MediaStore.Audio.Media.IS_ALARM, true);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);  
///new

But i did so much tweaking in this code, somehow i found the tutorial on how to make an alarm tone programmatically, and your own your way... just do the experiment!

dondondon
  • 881
  • 8
  • 4