如何从ringtonePicker对话框中选择铃声,并在按OK时在文本视图中显示

时间:2018-01-24 15:49:33

标签: android

here is the image

如何从ringtonePicker对话框中选择铃声,并在按下OK时将其显示在文本视图中,以及如何将默认复选框设置为'默认铃声&#39 ;;目前它位于' Andromeda'

1 个答案:

答案 0 :(得分:0)

我就是这样做的,只需替换你需要的类型的铃声类型。 显示对话框:

private void getNotificationSound() {
        Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Alert Tone");
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
        this.startActivityForResult(intent, 8);
    }

获取用户选择:

@Override
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
        if (resultCode == Activity.RESULT_OK && requestCode == 8) {
            Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            if (uri != null) {

                Log.d(TAG, uri.toString());
                Ringtone ringtone = RingtoneManager.getRingtone(this, uri);
                String title = ringtone.getTitle(this);
                tvSoundName.setText("Alert Sound: " + title);
            }
        }
    }