Example usage for android.media RingtoneManager EXTRA_RINGTONE_EXISTING_URI

List of usage examples for android.media RingtoneManager EXTRA_RINGTONE_EXISTING_URI

Introduction

In this page you can find the example usage for android.media RingtoneManager EXTRA_RINGTONE_EXISTING_URI.

Prototype

String EXTRA_RINGTONE_EXISTING_URI

To view the source code for android.media RingtoneManager EXTRA_RINGTONE_EXISTING_URI.

Click Source Link

Document

Given to the ringtone picker as a Uri .

Usage

From source file:Main.java

public static void pickRing(Activity activity) {
    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");

    if (mRingUri != null) {
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, mRingUri);
    } else {/*from  ww w . ja v  a  2s  . c o  m*/
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
    }
    activity.startActivityForResult(intent, RESULT_PICK_RING);
}

From source file:org.kontalk.ui.prefs.NotificationFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences_notification);

    // set ringtone
    final Preference setRingtone = findPreference("pref_ringtone");
    setRingtone.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override/*  w  w w. ja v a 2s .c o  m*/
        public boolean onPreferenceClick(Preference preference) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(preference.getContext());

            String _currentRingtone = prefs.getString(preference.getKey(),
                    getString(R.string.pref_default_ringtone));
            Uri currentRingtone = !TextUtils.isEmpty(_currentRingtone) ? Uri.parse(_currentRingtone) : null;

            final Intent i = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            i.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentRingtone);
            i.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
            i.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

            i.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
            i.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
            i.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, preference.getTitle());

            startActivityForResult(i, REQUEST_PICK_RINGTONE);
            return true;
        }
    });

    // notification LED color
    final Preference notificationLed = findPreference("pref_notification_led_color");
    notificationLed.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Context context = getContext();
            int[] ledColors = new int[] { ContextCompat.getColor(context, android.R.color.white),
                    ContextCompat.getColor(context, R.color.blue_light),
                    ContextCompat.getColor(context, R.color.purple_light),
                    ContextCompat.getColor(context, R.color.green_light),
                    ContextCompat.getColor(context, R.color.yellow_light),
                    ContextCompat.getColor(context, R.color.red_light), };

            try {
                new ColorChooserDialog.Builder((BasePreferencesActivity) getActivity(),
                        R.string.pref_notification_led_color).customColors(ledColors, null)
                                .preselect(Preferences.getNotificationLEDColor(getContext()))
                                .allowUserColorInput(false).dynamicButtonColor(false).show();
            } catch (IllegalStateException e) {
                // fragment is being destroyed - ignore
            }
            return true;
        }
    });
}

From source file:org.apache.cordova.ringtonepicker.RingtonePicker.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    this.callbackContext = callbackContext;
    if (action.equals("getRingtone")) {
        Log.d("customPlugin", " getRingtone ");

        Runnable getRingtone = new Runnable() {

            @Override/*from   w  ww.j a va 2  s .  co m*/
            public void run() {
                Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select ringtone for notifications:");
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
                notification_uri = Settings.System.getString(cordova.getActivity().getContentResolver(),
                        Settings.System.NOTIFICATION_SOUND);
                if (notification_uri == null) {
                    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
                } else {
                    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(notification_uri));
                }
                cordova.setActivityResultCallback(RingtonePicker.this);
                cordova.getActivity().startActivityForResult(intent, 5);
            }
        };
        this.cordova.getActivity().runOnUiThread(getRingtone);
        return true;
    } else {
        return false;
    }
}

From source file:org.apache.cordova.stringtoimagefile.StringToImageFile.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    this.callbackContext = callbackContext;
    if (action.equals("stringToImage")) {
        Log.d("customPlugin", "stringToImage ");

        Runnable getRingtone = new Runnable() {

            @Override/*from www .  jav  a  2s  .c o m*/
            public void run() {
                Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select ringtone for notifications:");
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
                notification_uri = Settings.System.getString(cordova.getActivity().getContentResolver(),
                        Settings.System.NOTIFICATION_SOUND);
                if (notification_uri == null) {
                    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
                } else {
                    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(notification_uri));
                }
                cordova.setActivityResultCallback(StringToImageFile.this);
                cordova.getActivity().startActivityForResult(intent, 5);
            }
        };
        this.cordova.getActivity().runOnUiThread(getRingtone);
        return true;
    } else {
        return false;
    }
}

From source file:com.microsoft.mimickeralarm.settings.RingtonePreference.java

private void onPrepareRingtonePickerIntent(Intent ringtonePickerIntent) {
    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, getRingtone());
    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
            GeneralUtilities.defaultRingtone());
    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALL);
    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getTitle());
}

From source file:id.satusatudua.sigap.ui.fragment.SettingFragment.java

@OnClick(R.id.ringtone)
public void chooseRingtone() {
    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Pilih Nada Dering");
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
            CacheManager.pluck().getRingtone() == null ? null : Uri.parse(CacheManager.pluck().getRingtone()));
    startActivityForResult(intent, 5);/*from   w  ww .ja  v a  2s  .  c  o m*/
}

From source file:org.proninyaroslav.libretorrent.settings.BehaviorSettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final SettingsManager pref = new SettingsManager(getActivity().getApplicationContext());

    String keyTorrentFinishNotify = getString(R.string.pref_key_torrent_finish_notify);
    SwitchPreferenceCompat torrentFinishNotify = (SwitchPreferenceCompat) findPreference(
            keyTorrentFinishNotify);/*from  w  ww . j av  a  2 s .  com*/
    torrentFinishNotify.setChecked(pref.getBoolean(keyTorrentFinishNotify, true));
    bindOnPreferenceChangeListener(torrentFinishNotify);

    String keyPlaySound = getString(R.string.pref_key_play_sound_notify);
    SwitchPreferenceCompat playSound = (SwitchPreferenceCompat) findPreference(keyPlaySound);
    playSound.setChecked(pref.getBoolean(keyPlaySound, true));
    bindOnPreferenceChangeListener(playSound);

    final String keyNotifySound = getString(R.string.pref_key_notify_sound);
    Preference notifySound = findPreference(keyNotifySound);
    String ringtone = pref.getString(keyNotifySound,
            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString());
    notifySound
            .setSummary(RingtoneManager.getRingtone(getActivity().getApplicationContext(), Uri.parse(ringtone))
                    .getTitle(getActivity().getApplicationContext()));
    /* See https://code.google.com/p/android/issues/detail?id=183255 */
    notifySound.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                    Settings.System.DEFAULT_NOTIFICATION_URI);

            String curRingtone = pref.getString(keyNotifySound, null);
            if (curRingtone != null) {
                if (curRingtone.length() == 0) {
                    // Select "Silent"
                    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
                } else {
                    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(curRingtone));
                }

            } else {
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
                        Settings.System.DEFAULT_NOTIFICATION_URI);
            }

            startActivityForResult(intent, REQUEST_CODE_ALERT_RINGTONE);

            return true;
        }
    });

    String keyLedIndicator = getString(R.string.pref_key_led_indicator_notify);
    SwitchPreferenceCompat ledIndicator = (SwitchPreferenceCompat) findPreference(keyLedIndicator);
    ledIndicator.setChecked(pref.getBoolean(keyLedIndicator, true));
    bindOnPreferenceChangeListener(ledIndicator);

    String keyLedIndicatorColor = getString(R.string.pref_key_led_indicator_color_notify);
    LightPreference ledIndicatorColor = (LightPreference) findPreference(keyLedIndicatorColor);
    ledIndicatorColor.forceSetValue(pref.getInt(keyLedIndicatorColor,
            ContextCompat.getColor(getActivity().getApplicationContext(), R.color.primary)));
    bindOnPreferenceChangeListener(ledIndicatorColor);

    String keyVibration = getString(R.string.pref_key_vibration_notify);
    SwitchPreferenceCompat vibration = (SwitchPreferenceCompat) findPreference(keyVibration);
    vibration.setChecked(pref.getBoolean(keyVibration, true));
    bindOnPreferenceChangeListener(vibration);

    String keyAutostart = getString(R.string.pref_key_autostart);
    SwitchPreferenceCompat autostart = (SwitchPreferenceCompat) findPreference(keyAutostart);
    autostart.setChecked(pref.getBoolean(keyAutostart, false));
    bindOnPreferenceChangeListener(autostart);

    String keyShutdownComplete = getString(R.string.pref_key_shutdown_downloads_complete);
    SwitchPreferenceCompat shutdownComplete = (SwitchPreferenceCompat) findPreference(keyShutdownComplete);
    shutdownComplete.setChecked(pref.getBoolean(keyShutdownComplete, false));
    bindOnPreferenceChangeListener(shutdownComplete);

    String keyCpuSleep = getString(R.string.pref_key_cpu_do_not_sleep);
    SwitchPreferenceCompat cpuSleep = (SwitchPreferenceCompat) findPreference(keyCpuSleep);
    cpuSleep.setChecked(pref.getBoolean(keyCpuSleep, false));
    bindOnPreferenceChangeListener(cpuSleep);

    String keyOnlyCharging = getString(R.string.pref_key_download_and_upload_only_when_charging);
    SwitchPreferenceCompat onlyCharging = (SwitchPreferenceCompat) findPreference(keyOnlyCharging);
    onlyCharging.setChecked(pref.getBoolean(keyOnlyCharging, false));
    bindOnPreferenceChangeListener(onlyCharging);

    String keyBatteryControl = getString(R.string.pref_key_battery_control);
    SwitchPreferenceCompat batteryControl = (SwitchPreferenceCompat) findPreference(keyBatteryControl);
    batteryControl.setSummary(
            String.format(getString(R.string.pref_battery_control_summary), Utils.getDefaultBatteryLowLevel()));
    batteryControl.setChecked(pref.getBoolean(keyBatteryControl, false));
    bindOnPreferenceChangeListener(batteryControl);
}

From source file:org.isoron.uhabits.helpers.ReminderHelper.java

public static void startRingtonePickerActivity(Fragment fragment, int requestCode) {
    Uri existingRingtoneUri = ReminderHelper.getRingtoneUri(fragment.getContext());
    Uri defaultRingtoneUri = Settings.System.DEFAULT_NOTIFICATION_URI;

    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, defaultRingtoneUri);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, existingRingtoneUri);
    fragment.startActivityForResult(intent, requestCode);
}

From source file:org.proninyaroslav.libretorrent.settings.AppearanceSettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final SettingsManager pref = new SettingsManager(getActivity().getApplicationContext());

    String keyTheme = getString(R.string.pref_key_theme);
    ListPreference theme = (ListPreference) findPreference(keyTheme);
    int type = pref.getInt(keyTheme, Integer.parseInt(getString(R.string.pref_theme_light_value)));
    theme.setValueIndex(type);//from  w w  w  .j  a  v  a 2  s .c  o m
    String typesName[] = getResources().getStringArray(R.array.pref_theme_entries);
    theme.setSummary(typesName[type]);
    bindOnPreferenceChangeListener(theme);

    String keyTorrentFinishNotify = getString(R.string.pref_key_torrent_finish_notify);
    SwitchPreferenceCompat torrentFinishNotify = (SwitchPreferenceCompat) findPreference(
            keyTorrentFinishNotify);
    torrentFinishNotify.setChecked(pref.getBoolean(keyTorrentFinishNotify, true));
    bindOnPreferenceChangeListener(torrentFinishNotify);

    String keyPlaySound = getString(R.string.pref_key_play_sound_notify);
    SwitchPreferenceCompat playSound = (SwitchPreferenceCompat) findPreference(keyPlaySound);
    playSound.setChecked(pref.getBoolean(keyPlaySound, true));
    bindOnPreferenceChangeListener(playSound);

    final String keyNotifySound = getString(R.string.pref_key_notify_sound);
    Preference notifySound = findPreference(keyNotifySound);
    String ringtone = pref.getString(keyNotifySound,
            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString());
    notifySound
            .setSummary(RingtoneManager.getRingtone(getActivity().getApplicationContext(), Uri.parse(ringtone))
                    .getTitle(getActivity().getApplicationContext()));
    /* See https://code.google.com/p/android/issues/detail?id=183255 */
    notifySound.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                    Settings.System.DEFAULT_NOTIFICATION_URI);

            String curRingtone = pref.getString(keyNotifySound, null);
            if (curRingtone != null) {
                if (curRingtone.length() == 0) {
                    // Select "Silent"
                    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
                } else {
                    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(curRingtone));
                }

            } else {
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
                        Settings.System.DEFAULT_NOTIFICATION_URI);
            }

            startActivityForResult(intent, REQUEST_CODE_ALERT_RINGTONE);

            return true;
        }
    });

    String keyLedIndicator = getString(R.string.pref_key_led_indicator_notify);
    SwitchPreferenceCompat ledIndicator = (SwitchPreferenceCompat) findPreference(keyLedIndicator);
    ledIndicator.setChecked(pref.getBoolean(keyLedIndicator, true));
    bindOnPreferenceChangeListener(ledIndicator);

    String keyLedIndicatorColor = getString(R.string.pref_key_led_indicator_color_notify);
    ColorPreference ledIndicatorColor = (ColorPreference) findPreference(keyLedIndicatorColor);
    ledIndicatorColor.forceSetValue(pref.getInt(keyLedIndicatorColor,
            ContextCompat.getColor(getActivity().getApplicationContext(), R.color.primary)));
    bindOnPreferenceChangeListener(ledIndicatorColor);

    String keyVibration = getString(R.string.pref_key_vibration_notify);
    SwitchPreferenceCompat vibration = (SwitchPreferenceCompat) findPreference(keyVibration);
    vibration.setChecked(pref.getBoolean(keyVibration, true));
    bindOnPreferenceChangeListener(vibration);
}

From source file:com.mattprecious.notisync.profile.SecondaryCustomProfileActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.profile_custom_secondary);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    dbAdapter = new DbAdapter(this);

    if (getIntent().hasExtra("profile")) {
        profile = getIntent().getParcelableExtra("profile");
    } else {//from   w w  w .j a v a  2 s.  co  m
        profile = new SecondaryProfile();
        profile.setEnabled(true);
        profile.setVibrate(true);
        profile.setLed(true);
    }

    nameField = (EditText) findViewById(R.id.nameField);
    nameField.setText(profile.getName());
    nameField.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                validateName();

                if (tagField.getText().length() == 0) {
                    tagField.setText(nameField.getText().toString().toLowerCase(Locale.getDefault())
                            .replaceAll("\\s", ""));
                    validateTag();
                }
            }
        }

    });

    tagField = (EditText) findViewById(R.id.tagField);
    tagField.setText(profile.getTag());
    tagField.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                validateTag();
            }

        }

    });

    tagRequestButton = (ImageButton) findViewById(R.id.tagRequestButton);
    tagRequestButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            SherlockDialogFragment newFragment = new RequestTagsDialogFragment();
            newFragment.show(getSupportFragmentManager(), null);
        }

    });

    unconnectedOnlyCheckBox = (CheckBox) findViewById(R.id.unconnectedOnlyCheckBox);
    unconnectedOnlyCheckBox.setChecked(profile.isUnconnectedOnly());

    ringtoneSelector = (Button) findViewById(R.id.ringtoneSelector);
    ringtoneSelector.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, getRingtoneUri(profile.getRingtone()));

            startActivityForResult(intent, REQUEST_CODE_RINGTONE_PICKER);

        }
    });

    vibrateCheckBox = (CheckBox) findViewById(R.id.vibrateCheckBox);
    vibrateCheckBox.setChecked(profile.isVibrate());

    checkForVibrator();

    lightsCheckBox = (CheckBox) findViewById(R.id.lightsCheckBox);
    lightsCheckBox.setChecked(profile.isLed());

    updateRingtoneSelector();
}