1

我正在尝试在模拟器/手机上添加和设置默认铃声。铃声已下载并存储在应用程序文件夹 /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

我在许多论坛中搜索过解决方案,但找不到任何解决方案。

任何帮助都是最受欢迎的

谢谢

4

0 回答 0