2011-07-27 2 views
0
을 수행하지

편집 :설정 벨소리 클래스는 아무것도

전체 SetRingtone.java -

public class SetRingtone extends Activity{ 

String TAG = "CFFS"; // Class var for logging - identifies the app in the logcat 

public boolean saveas(int ressound){ 
     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 = Environment.getExternalStorageDirectory().getPath() + "/media/ringtone/ringtone.mp3"; 
     String filename="College Football Fight Song"+".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, "College Football Fight Song"); 
    values.put(MediaStore.MediaColumns.SIZE, 215454); 
    values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); 
    values.put(MediaStore.Audio.Media.ARTIST, ""); 
    values.put(MediaStore.Audio.Media.DURATION, 230); 
    values.put(MediaStore.Audio.Media.IS_RINGTONE, true); 
    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); 
    values.put(MediaStore.Audio.Media.IS_ALARM, false); 
    values.put(MediaStore.Audio.Media.IS_MUSIC, false); 

    //Insert it into the database 

    Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()); 

    getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + k.getAbsolutePath() + "\"", null); 

    Uri newUri = getContentResolver().insert(uri, values); 

    RingtoneManager.setActualDefaultRingtoneUri(
      SetRingtone.this, 
     RingtoneManager.TYPE_RINGTONE, 
     newUri 
    ); 

    return false; 
} 

자바 내가 벨소리 설정하려는 -

private OnLongClickListener onLongImageClick = new OnLongClickListener() { 
    @Override 
    public boolean onLongClick(View v) { 
     if (v.getId() == R.id.boston_college_imageview) { 
      SetRingtone(R.raw.acc_boston_college); 
     } 
     return false; 
     } 
}; 

을하고 내가 어디 통과 SetRingtone.java로 이동 -

private void SetRingtone(int soundID) { 
    Intent otherIntent = new Intent(); 
    otherIntent.setClassName("com.carboni.fightsongs", "com.carboni.fightsongs.SetRingtone"); 
    otherIntent.putExtra("com.carboni.fightsongs.FILE_RES_ID", soundID); 
    startActivity(otherIntent); 
} 
+0

디버그 코드 라인과 예외가 어딘가가 있는지. try-catch에있는 코드에 문제가있는 경우 오류가 표시되지 않습니다. –

+0

좋아, 나는 그것을 시도 할 것이다. 그러나 당신이 볼 수있는 것에서, 틀리게 보이는 것이 있습니까? – ericcarboni

+0

contentresolver의 모든 특성에 대한 값을 입력해야 할 수도 있습니다. 'getContentResolver()'대신'context.getContentResolver()'를해야 할 수도 있습니다. 또한 파일 경로가 잘못되었을 수 있습니다. [this] (http://stackoverflow.com/questions/1271777/how-to-set-ringtone-in-android-from-my-activity)와 [this] (http://coderzheaven.com)을 살펴보십시오./2010/10/how-to-set-ringtone-in-android /)를 참조하십시오. –

답변

0

imageView1.setOnLongClickListener(new ImageView.OnLongClickListener() 
{ 
    public boolean onLongClick(View v) 
    { 
     if (v.getId() == R.id.boston_college_imageview) 
     { 
      SetRingtone(R.raw.acc_boston_college); 
     } 
     return false; 
    } 
}); 

UPDATE : 긴 클릭은 이미지 뷰에 어떻게 보일지이야 라인으로

String path = Environment.getExternalStorageDirectory().getPath() + "/media/ringtone"; 
String filename="College Football Fight Song.mp3"; 

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

FileOutputStream save; 
try 
{ 
    File file = new File(path, filename); 
    save = new FileOutputStream(file); 
    save.write(buffer); 
    save.flush(); 
    save.close(); 
} 
catch (FileNotFoundException e) 
{ 
    return false; 
} 
catch (IOException e) 
{ 
    return false; 
} 
+0

여전히 작동하지 않는 것 같습니다. 나는 많은 다른 것들을 시도했고, 이제는 벨소리를 전혀 바꾸지 않습니다. 다시있을 예정인 벨소리의 경로는 무엇입니까? – ericcarboni

+0

나는 다음과 같이 보일 것입니다 :'// String path = "/sdcard/media/ringtone/ringtone.mp3;' 'String path = Environment.getExternalStorageDirectory(). getPath() +"/ media/ringtone/ringtone . –

+0

왜 'path'문자열이 두 번 선언 되었습니까? – ericcarboni