2013-06-18 4 views
0

미리 정의 된/구성 가능한 목록에서 오디오 파일 (벨소리)을 무작위로 선택한 응용 프로그램을 작성하고 전화를받을 때 재생할 수 있는지 궁금합니다. 그래서 나는 같은 사람이 연속적으로 부름을받을 때도 내 벨소리가 바뀔 것입니다.전화를받을 때마다 다른 소리가납니다

이것이 가능합니까? 그렇다면 얼마나 복잡할까요? 공급자 또는 OS에 대한 의존성을 고려해야합니까?

+3

http://stackoverflow.com/questions/6182891/how-can-i-change-the-ringtone-in-android-programmatically하는 데 도움이 – Blackbelt

답변

1

사용은 http://www.androidapps.com/t/rings-extended

솔루션은 당신이 삽입 컨텐츠 해결에 제공하기 전에, 리소스 파일 자산을 얻고 sdcard에 1 일에 작성하는 것입니다 "반지는 확장".

File newSoundFile = new File("/sdcard/media/ringtone", "myringtone.oog"); 
Uri mUri = Uri.parse("android.resource://com.your.package/R.raw.your_resource_id"); 
ContentResolver mCr = app.getContentResolver(); 
AssetFileDescriptor soundFile; 
try { 
     soundFile= mCr.openAssetFileDescriptor(mUri, "r"); 
    } catch (FileNotFoundException e) { 
     soundFile=null; 
    } 

    try { 
     byte[] readData = new byte[1024]; 
     FileInputStream fis = soundFile.createInputStream(); 
     FileOutputStream fos = new FileOutputStream(newSoundFile); 
     int i = fis.read(readData); 

     while (i != -1) { 
     fos.write(readData, 0, i); 
     i = fis.read(readData); 
     } 

     fos.close(); 
    } catch (IOException io) { 
    } 
Then you can use the previously posted solution 

     ContentValues values = new ContentValues(); 
    values.put(MediaStore.MediaColumns.DATA, newSoundFile.getAbsolutePath()); 
    values.put(MediaStore.MediaColumns.TITLE, "my ringtone"); 
    values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/oog"); 
    values.put(MediaStore.MediaColumns.SIZE, newSoundFile.length()); 
    values.put(MediaStore.Audio.Media.ARTIST, R.string.app_name); 
    values.put(MediaStore.Audio.Media.IS_RINGTONE, true); 
    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true); 
    values.put(MediaStore.Audio.Media.IS_ALARM, true); 
    values.put(MediaStore.Audio.Media.IS_MUSIC, false); 

    Uri uri = MediaStore.Audio.Media.getContentUriForPath(newSoundFile.getAbsolutePath()); 
    Uri newUri = mCr.insert(uri, values); 


    try { 
     RingtoneManager.setActualDefaultRingtoneUri(getContext(), RingtoneManager.TYPE_RINGTONE, newUri); 
    } catch (Throwable t) { 
     Log.d(TAG, "catch exception"); 
    } 

희망이

관련 문제