Android
[안드로이드] 벨소리 설정법
아낙시만더
2010. 12. 20. 14:06
반응형
Code Endprivate Runnable BuyTheMusic = new Runnable() { public void run() { //TODO 파일을 다운로딩하는 스레드 //URL 생성 tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); DownloadURL = "http://smartring.wiz.co.kr/bell/wiz_009.asp?key=" + CyptoPhone + "&id=" + CyptoLid + "&subno=" + SelectURL; switch (SelectURL) { case 1: mp_text = "_후렴"; break; case 2: mp_text = "_앞부분"; break; case 3: mp_text = "_뒷부분"; break; default: mp_text = ""; break; } //파일 정보 설정 k = new File("/sdcard/wiz/bellmusic",music.getSongName() +"-"+music.getSingerName() + mp_text + ".mp3"); try { inputStream = new URL(DownloadURL).openStream(); songTitle = music.getSongName(); artist = music.getSingerName(); myDuration = 0; // 만약 파일 디스크립트가 존재 하지 않는다면 if (!k.isFile()) { // 파일이 속한 부모폴더의 경로를 가져와서 부모의 파일 디스크립터를 만든다. File fParent = new File(k.getParent()); // 부모가 없다면 if (!fParent.exists()) { // 부모 파일 디스크립터를 가져와서 새로운 디스크립터를 만든다. File wizRoot = new File(fParent.getParent()); // 새로운 디스크립터가 없다면 if (!wizRoot.exists()) { // brt에 새로운 디스크립터를 다시 할당하는 작업을 시도한다. bRet = wizRoot.mkdir(); } // 부모폴더의 패스를 가져온다. fParent.mkdir(); } // 파일을 만들고 디스크립터 k에연결시킨다. k.createNewFile(); // 스레드를 돌며 파일을 1바이트씩 가져와 로컬 영역에 저장한다. trans= new Thread() { public void run() { try { FileOutputStream out = new FileOutputStream(k); byte[] bBuffer = new byte[1024 * 8]; int nRead; while ((nRead = inputStream.read(bBuffer)) != -1) { System.out.println("nRead size : " + nRead); out.write(bBuffer, 0, nRead); } out.close(); inputStream.close(); Thread.sleep(2000); handler.sendEmptyMessage(0);// 파일 다운로딩이 끝나면 성공 했다는 알람 창을 뛰운다. } catch (Exception e) { } } }; trans.start(); } else if (k.isFile()) {//파일이 존재하면 이미존재한다는 경고창을 뛰운다. 스레드 종료 mProgress.dismiss(); BellSetActivity.this.removeDialog(1); handler.post(updateResult2); } else { Log.e("DRAGON", "error --> file not exist"); } } catch (Exception e) { Log.e("DRAGON", "error --> set ringtone: " + e.getMessage()); e.printStackTrace(); } } }; // 핸들러 동작 정의 private Handler handler = new Handler() { public void handleMessage(Message msg) { Log.i("DRAGON", "info -- > file exist"); ContentValues values = new ContentValues(); values.put(MediaStore.Audio.Media.DATA, k.getAbsolutePath()); values.put(MediaStore.Audio.Media.TITLE, songTitle + mp_text); values.put(MediaStore.Audio.Media.SIZE, k.length()); values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/mp3"); values.put(MediaStore.Audio.Media.ARTIST, artist); values.put(MediaStore.Audio.Media.DURATION, myDuration); // 받은 파일을 현재 링톤으로 셋팅한다. values.put(MediaStore.Audio.Media.IS_RINGTONE, true); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); values.put(MediaStore.Audio.Media.IS_ALARM, true); values.put(MediaStore.Audio.Media.IS_MUSIC, false); //Uri uri = MediaStore.Audio.Media.getContentUriForPath(k // .getAbsolutePath()); // Insert it into the database Log.i("DRAGON", "info --> insert database"); Uri newUri = BellSetActivity.this.getContentResolver().insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values); //벨소리 설정 RingtoneManager.setActualDefaultRingtoneUri(BellSetActivity.this, RingtoneManager.TYPE_RINGTONE, newUri); String model = Build.MODEL; //단말기 모델명을 확인한다. model= model.replaceAll(" ", ""); //과금 후 결과감 리턴 String Check = new TextDownloadStream().DownloadPhoneNum( "http://smartring.wiz.co.kr/bell/wiz_004.asp?id=" + CyptoLid + "&subno=" + SelectURL + "&did=" + tm.getDeviceId() + "&key=" + CyptoPhone + "&os="+model); System.out.println("Check : "+Check); mProgress.dismiss(); BellSetActivity.this.removeDialog(1); trans.interrupt(); TimeFlag = false; showDialog(4);// 성공 메세지 } };
반응형