1

旨在尝试将铃声从我的应用程序传输到用户 sdcard 一切正常

但是当我尝试保存另一个铃声时,该功能将旧铃声和新铃声保存为同一个 mp3 文件

就像我第一次保存 lol.mp3 它的工作,当我保存另一个像 hora.mp3

将 mora.mp3 和 lol.mp3 保存为 hora.mp3 的同一文件如何解决此问题!

public boolean saveas(int ressound , String ringname , Boolean isringtone , Boolean isnotificatoion  ){

        byte[] buffer=null;
        InputStream fIn = getBaseContext().getResources().openRawResource(ressound);
        int size=0;

        try {
        size = fIn.available();
        buffer = new byte[size];
        fIn.read(buffer);
        fIn.close();
        } catch (IOException e) {
        // TODO Auto-generated catch block
        return false;
        }

        String path="/sdcard/Islamyat/";
        String filename="mysound"+".mp3";

        boolean exists = (new File(path)).exists();
        if (!exists){new File(path).mkdirs();}

        FileOutputStream save;
        try {
        save = new FileOutputStream(path+filename);
        save.write(buffer);
        save.flush();
        save.close();
        } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        return false;
        } catch (IOException e) {
        // TODO Auto-generated catch block
        return false;
        }

        sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename)));

        File k = new File(path, filename);

        ContentValues values = new ContentValues();
        values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
        values.put(MediaStore.MediaColumns.TITLE, ringname);
        values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
        values.put(MediaStore.Audio.Media.ARTIST, "yappname");
        values.put(MediaStore.Audio.Media.IS_RINGTONE, isringtone);
        values.put(MediaStore.Audio.Media.IS_NOTIFICATION, isnotificatoion);
        values.put(MediaStore.Audio.Media.IS_ALARM, false);
        values.put(MediaStore.Audio.Media.IS_MUSIC, false);

        //Insert it into the database
        Uri newUri= this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);

        RingtoneManager.setActualDefaultRingtoneUri(
        this,
        RingtoneManager.TYPE_RINGTONE,
        newUri
        );
        return true;
        }
4

0 回答 0