如何使用服务器的铃声设置默认铃声

时间:2015-05-19 06:26:44

标签: android ringtone

我正在尝试使用服务器中的铃声设置默认铃声。所以,首先我尝试使用以下代码将我的铃声从url下载到SD卡:

InputStream input = new BufferedInputStream(url.openStream());
    File sdCard = Environment.getExternalStorageDirectory();
    File dir = new File (sdCard.getAbsolutePath() + "/myfoldername/dir3");
    dir.mkdirs();
    File file = new File(dir, myringtonename + ".mp3");
    FileOutputStream output = new FileOutputStream(file);

但是铃声会节省手机存储而不是SD卡。 之后,我尝试使用以下代码从SD卡设置铃声:

private void setrington() {
            String path = getFilesDir()+"/sdcard/myfoldername/dir3/";
            File k = new File(path, myringtonename + ".mp3"); // path is a file to /sdcard/media/ringtone
            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, "Madonna");
            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);
            Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
Uri newUri = Etelaat.this.getContentResolver().insert(uri, values);
RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(),RingtoneManager.TYPE_RINGTONE,newUri);

        }

设置铃声代码不起作用,我在logcat中看到了这个注释:

05-19 01:26:23.841: V/Provider/Settings(3485):  from settings cache , name = sound_effects_enabled , value = 0
05-19 01:26:23.848: D/ActivityThread(3485): hoder:android.app.IActivityManager$ContentProviderHolder@42ce86c0,provider,holder.Provider:android.content.ContentProviderProxy@42ce9098
05-19 01:26:23.979: D/Provider/Settings(3485): put string name = ringtone , value = content://media/internal/audio/media/142 userHandle = 0
05-19 01:26:24.031: I/RingtoneManager(3485): Set actual default ringtone uri= content://media/internal/audio/media/142

我也尝试过这个:

File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/myfoldername/dir3");
dir.mkdirs();
File file = new File(dir, myringtonename + ".mp3");

甚至,它不起作用:

05-19 01:36:22.478: V/Provider/Settings(7367):  from settings cache , name = sound_effects_enabled , value = 0
05-19 01:36:22.494: D/ActivityThread(7367): hoder:android.app.IActivityManager$ContentProviderHolder@42cce4c8,provider,holder.Provider:android.content.ContentProviderProxy@42cceea0
05-19 01:36:22.606: D/Provider/Settings(7367): put string name = ringtone , value = null userHandle = 0
05-19 01:36:22.631: I/RingtoneManager(7367): Set actual default ringtone uri= null

0 个答案:

没有答案