Skip to content Skip to sidebar Skip to footer

How To Set Ringtone Through An Android Application?

I am trying set a ringtone through my android application. I tried with this code public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); se

Solution 1:

Stringfilepath="/sdcard/Fast_N_Furious_2009.mp3";
    FileringtoneFile=newFile(filepath);

    ContentValuescontent=newContentValues();
    content.put(MediaStore.MediaColumns.DATA,ringtoneFile.getAbsolutePath());
    content.put(MediaStore.MediaColumns.TITLE, "chinnu");
    content.put(MediaStore.MediaColumns.SIZE, 215454);
    content.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
    content.put(MediaStore.Audio.Media.ARTIST, "Madonna");
    content.put(MediaStore.Audio.Media.DURATION, 230);
    content.put(MediaStore.Audio.Media.IS_RINGTONE, true);
    content.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
    content.put(MediaStore.Audio.Media.IS_ALARM, false);
    content.put(MediaStore.Audio.Media.IS_MUSIC, false);


    //Insert it into the database
    Log.i(TAG, "the absolute path of the file is :"+
    ringtoneFile.getAbsolutePath());
    Uriuri= MediaStore.Audio.Media.getContentUriForPath(ringtoneFile.getAbsolutePath());
    //Uri newUri = context.getContentResolver().insert(uri, content);UrinewUri= getContentResolver().insert(uri, content); 
    StringringtoneUri= newUri.toString();

    Log.i(TAG,"the ringtone uri is :"+ringtoneUri);
    RingtoneManager.setActualDefaultRingtoneUri(getBaseContext(),RingtoneManager.TYPE_RINGTONE,newUri);

Solution 2:

hi Sarath if r try in your activity the remove the Context in your code.

replace the line

Uri newUri = getContentResolver().insert(uri, content); ringtoneUri = newUri;

Post a Comment for "How To Set Ringtone Through An Android Application?"