Hello,

I have created an activity that copies an MP3 file from the assets to
the SD card, then sets that MP3 file as the default ringtone.

        // file is the file on the SD card
        ContentValues values = new ContentValues();
        values.put(MediaStore.MediaColumns.DATA,
file.getAbsolutePath());
        values.put(MediaStore.MediaColumns.TITLE, "my_title" );
        values.put(MediaStore.MediaColumns.SIZE, file.length());
        values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
        values.put(MediaStore.Audio.Media.ARTIST, "my_artist" );
        values.put(MediaStore.Audio.Media.DURATION, duration );
        values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
        values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
        values.put(MediaStore.Audio.Media.IS_ALARM, false);
        values.put(MediaStore.Audio.Media.IS_MUSIC, false);
        Uri uri =
MediaStore.Audio.Media.getContentUriForPath(file.getAbsolutePath());
        Uri ringtoneUri = getContentResolver().insert(uri, values);
 
RingtoneManager.setActualDefaultRingtoneUri( this 
,RingtoneManager.TYPE_RINGTONE,
ringtoneUri );

That works fine.
What I want to do now is to set a custom ringtone for a specific
contact.
I tried this.

                Uri contactUri =
ContentUris.withAppendedId(People.CONTENT_URI, 23 );
                ContentValues values = new ContentValues();
                values.put( ContactsContract.Contacts.CUSTOM_RINGTONE,
ringtoneUri.toString() );
                values.put( Contacts.PeopleColumns.CUSTOM_RINGTONE,
ringtoneUri.toString() );
                getContentResolver().update( contactUri, values, null,
null ); //where, args );

This does not work.
The ringtone is not assigned to the contact.
Can anyone help ?
What I am doing wrong ?

Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to