android保存重复铃声保存

时间:2013-03-27 23:48:56

标签: java android

瞄准尝试将铃声从我的应用程序转移到用户SD卡,每件事情都很好

但是当我尝试保存另一个铃声时,该功能会将旧铃声和新铃声保存为相同的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;
        }

0 个答案:

没有答案