2012-01-15 24 views
0

次のコードを試しても、着信音は設定されません。 "ff"のlogcatエントリは、URIが正しく連結されていないと思いますので、私のコードでどこが間違っているのかわかりません。Androidセットの着信音のエラー

String filepath =Environment.getExternalStorageDirectory().toString()+"//media//audio//ringtones//bluemoon.mp3"; 
       File ringtoneFile = new File(filepath); 
       ContentValues content = new ContentValues(); 
       content.put(MediaStore.MediaColumns.DATA,ringtoneFile.getAbsolutePath()); 
       content.put(MediaStore.MediaColumns.TITLE, "test"); 
       content.put(MediaStore.MediaColumns.SIZE, 215454); 
       content.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mpeg"); 
       content.put(MediaStore.Audio.Media.ARTIST, "artist"); 
       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); 
       Log.i("BOOM", "the absolute path of the file is :"+ringtoneFile.getAbsolutePath()); 
       Uri uri = MediaStore.Audio.Media.getContentUriForPath(
       ringtoneFile.getAbsolutePath()); 
       Uri newUri = getApplicationContext().getContentResolver().insert(uri, content); 
       Uri ringtoneUri = newUri; 
       Log.i("ff","the ringtone uri is :"+ringtoneUri); 
       RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(), 
       RingtoneManager.TYPE_RINGTONE,newUri); 

答えて

0

その可能性のあるデータは、ファイルとその問題の原因となります。あなたは変更する必要があります:audio/mp3

duration

audio/mpegファイルの実際の期間に。

修正したいことがもう一つは、あなたの着信音ファイルの宣言文で、それはこれと一致するように変更してみてください..

File k = new File(path, "mysong.mp3"); 
また

、私は感じてあなたのパスがあまりにも壊れているの

Environment.getExternalStorageDirectory().toString()+"//media//audio//ringtones//bluemoon.mp3" 

2つの「//」はなぜですか?

それは、(例えば)する必要があります:私はC#で働いていた

../sdcard/media/ringtone 
+0

(//)何が悪かったのか知らない、おかげで – brux

関連する問題