'tone'에 해당되는 글 1건

  1. 2013.07.01 ringtone/alarm tone 설정

AndroidManifest.xml

    <uses-permission android:name="android.permission.WRITE_SETTINGS" />


    public void setAsRingTone(){

        String filePath = getSelectedFilePath();

        MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();

        metaRetriever.setDataSource(filePath);

        String durationStr = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);

        int duration = (int)Long.parseLong(durationStr);

        metaRetriever.release();


        File ringtoneFile = new File(filePath);

        ContentValues values = new ContentValues();

        values.put(MediaStore.MediaColumns.DATA, ringtoneFile.getAbsolutePath());

        values.put(MediaStore.MediaColumns.TITLE, "ocsoosoo");

        values.put(MediaStore.MediaColumns.SIZE, ringtoneFile.length());

        values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");

        values.put(MediaStore.Audio.Media.ARTIST, "ocsoosoo");

        values.put(MediaStore.Audio.Media.DURATION, duration);

        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(ringtoneFile.getAbsolutePath());

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


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

        Toast.makeText(this, "Completed.", Toast.LENGTH_SHORT).show();

    }


    public void setAsAlarmTone(){

        String filePath = getSelectedFilePath();

        MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();

        metaRetriever.setDataSource(filePath);

        String durationStr = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);

        int duration = (int)Long.parseLong(durationStr);

        metaRetriever.release();


        File ringtoneFile = new File(filePath);

        ContentValues values = new ContentValues();

        values.put(MediaStore.MediaColumns.DATA, ringtoneFile.getAbsolutePath());

        values.put(MediaStore.MediaColumns.TITLE, "ocsoosoo");

        values.put(MediaStore.MediaColumns.SIZE, ringtoneFile.length());

        values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");

        values.put(MediaStore.Audio.Media.ARTIST, "ocsoosoo");

        values.put(MediaStore.Audio.Media.DURATION, duration);

        values.put(MediaStore.Audio.Media.IS_RINGTONE, false);

        values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);

        values.put(MediaStore.Audio.Media.IS_ALARM, true);

        values.put(MediaStore.Audio.Media.IS_MUSIC, false);


        //Insert it into the database

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

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


        RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM, newUri);

        Toast.makeText(this, "Completed.", Toast.LENGTH_SHORT).show();

    }

저작자 표시 비영리 변경 금지
신고
크리에이티브 커먼즈 라이선스
Creative Commons License

'programmer > android' 카테고리의 다른 글

popupwindow example  (0) 2013.07.03
usb event broadcastreceiver  (0) 2013.07.03
ringtone/alarm tone 설정  (0) 2013.07.01
seekbar progress 위치에 value 표시  (0) 2013.06.25
android custom actionbar  (0) 2013.06.22
dialog position  (0) 2013.06.20
Posted by ocsoosoo

댓글을 달아 주세요

이전버튼 1 이전버튼

티스토리 툴바