エミュレーター/電話にデフォルトの着信音を追加して設定しようとしています。着信音がダウンロードされ、アプリケーションフォルダ/dada/dada/com.xxx/ringtonesに保存されています。着信音はoggファイルです。
次のコードを使用して、着信音を追加および設定します。
public void setRingtone() {
aajoAsset asset = null;
asset = mXXXX.getAssetManager().getCurrentRingtoneAsset();
if (asset != null && asset.isSaved()/* && !asset.getName().equals(mLastAssetName)*/) {
String filepath = asset.getDirectoryPath() + asset.getFilename();
File ringtoneFile = new File(filepath);
if (LOG) {
Log.i(TAG, "Sending Intent : " + Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
}
mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + asset.getDirectoryPath() + asset.getFilename())));
ContentValues content = new ContentValues();
content.put(MediaStore.MediaColumns.DATA,ringtoneFile.getAbsolutePath());
content.put(MediaStore.MediaColumns.TITLE, "1234");
content.put(MediaStore.MediaColumns.SIZE, asset.getSize());
content.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");
content.put(MediaStore.Audio.Media.ARTIST, "1234");
content.put(MediaStore.Audio.Media.DURATION, 4800);
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);
if (LOG) {
Log.i(TAG, "the absolute path of the file is : " + ringtoneFile.getAbsolutePath());
}
Uri uri = MediaStore.Audio.Media.getContentUriForPath(
ringtoneFile.getAbsolutePath());
Uri newUri = mContext.getContentResolver().insert(uri, content);
if (LOG) {
Log.i(TAG,"the ringtone uri is : " + newUri);
}
RingtoneManager.setActualDefaultRingtoneUri(mContext, RingtoneManager.TYPE_RINGTONE, newUri);
mLastAssetName = asset.getName();
}
コードは正常に実行され、着信音が着信音リストに表示されますが、それをクリックしてテストしたり、着信をシミュレートしたりすると、LogCatで次のエラーが発生します。
DEBUG/MediaPlayer(1230): Couldn't open file on client side, trying server side
ERROR/MediaPlayerService(33): Couldn't open fd for content://media/internal/audio/media/1
ERROR/MediaPlayer(1230): Unable to to create media player
ERROR/RingtoneManager(1230): Failed to open ringtone content://media/internal/audio/media/1
多くのフォーラムで解決策を検索しましたが、見つかりません。
どんな助けでも大歓迎です
ありがとう