如何在android中设置铃声?

时间:2010-09-19 17:40:43

标签: android ringtone

我认为这是一个奇怪的问题,但我没有任何线索可以解决它。我想从我的代码中设置铃声,但我无法设置它。我看到了这个问题.. Setting Ringtone in AndroidSetting Ringtone in Android

我使用此代码。

        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());

但我收到此错误

W / BackupManagerService(52):dataChanged但没有参与者pkg ='com.android.p roviders.settings'uid = 10024

我无法找到为什么我的代码会发生这种情况?我用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

我允许该应用..

<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>

请帮助我克服这个错误:((..

0 个答案:

没有答案