views:

66

answers:

1

Hi all, I think this is weird question , but i do not have any clue to solve it . I want to set ringtone from my code , butt i cannot set it. I saw this questions .. http://stackoverflow.com/questions/1986756/setting-ringtone-in-android and http://stackoverflow.com/questions/1986756/setting-ringtone-in-android

I use this code .

        ContentValues values = new ContentValues();
        values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
        values.put(MediaStore.MediaColumns.TITLE, "My Song title");
        values.put(MediaStore.MediaColumns.SIZE, 215454);
        values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
        values.put(MediaStore.Audio.Media.ARTIST, "");
        values.put(MediaStore.Audio.Media.DURATION, 230);
        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);

        //Insert it into the database
        Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
        Uri newUri = activity.getContentResolver().insert(uri, values);

        RingtoneManager.setActualDefaultRingtoneUri(myucontext ,RingtoneManager.TYPE_RINGTONE, newUri);                 

            Settings.System.putString(activity.getContentResolver(), Settings.System.RINGTONE, newUri.toString());

but i am getting this error

W/BackupManagerService( 52): dataChanged but no participant pkg='com.android.p roviders.settings' uid=10024

I cannot find why this is happening to my code ? I use log ..

// this is before  i set the ringtone 
D/testing (  232): New uricontent://media/external/audio/media/46
i set this uri to  RingtoneManager.setActualDefaultRingtoneUri
D/testing (  232): Default uricontent://settings/system/ringtone
After seting the uri when i read the value again i found this setings :((
D/dalvikvm(  221): GC freed 3861 objects / 221176 bytes in 95ms

I give permission to the app ..

<uses-permission android:name="android.permission.WRITE_SETTINGS" ></uses-permission>
      <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" ></uses-permission>
      <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" ></uses-permission>

Please help me overcome this error :(( ..

A: 

Actually it is not a error . as the emulator has no ringtone so it is giving this error . In the device the code works fine.

Tareq