下面列出了android.media.RingtoneManager#ACTION_RINGTONE_PICKER 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onClick() {
super.onClick();
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Sound");
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 existingValue = getValue();
if (existingValue != null) {
if (existingValue.length() == 0) {
// Select "Silent"
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
} else {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(existingValue));
}
} else {
// No ringtone has been selected, set to the default
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Settings.System.DEFAULT_NOTIFICATION_URI);
}
mParent.startActivityForResult(intent, REQUEST_CODE_ALERT_RINGTONE);
}
public void onSoundSettings() {
Uri current = Prefs.getChatRingtone(this, chatId);
Uri defaultUri = Prefs.getNotificationRingtone(this);
if (current == null) current = Settings.System.DEFAULT_NOTIFICATION_URI;
else if (current.toString().isEmpty()) current = null;
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, defaultUri);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, current);
startActivityForResult(intent, REQUEST_CODE_PICK_RINGTONE);
}
protected void ringtonePicker(@NonNull AlarmClockItem item)
{
int ringtoneType = RingtoneManager.TYPE_RINGTONE;
if (!AlarmSettings.loadPrefAllRingtones(this)) {
ringtoneType = (item.type == AlarmClockItem.AlarmType.NOTIFICATION ? RingtoneManager.TYPE_NOTIFICATION : RingtoneManager.TYPE_ALARM);
}
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, ringtoneType);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, item.type.getDisplayString());
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, AlarmSettings.getDefaultRingtoneUri(this, item.type));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (item.ringtoneURI != null ? Uri.parse(item.ringtoneURI) : null));
t_selectedItem = item.rowID;
startActivityForResult(intent, REQUEST_RINGTONE);
}
private void launchSoundSelector(@Nullable Uri current) {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, Settings.System.DEFAULT_NOTIFICATION_URI);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, current);
startActivityForResult(intent, RINGTONE_PICKER_REQUEST_CODE);
}
@Override
public boolean onPreferenceClick(Preference preference) {
Uri current;
Uri defaultUri;
if (calls) {
current = recipient.get().getCallRingtone();
defaultUri = TextSecurePreferences.getCallNotificationRingtone(getContext());
} else {
current = recipient.get().getMessageRingtone();
defaultUri = TextSecurePreferences.getNotificationRingtone(getContext());
}
if (current == null) current = Settings.System.DEFAULT_NOTIFICATION_URI;
else if (current.toString().isEmpty()) current = null;
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, defaultUri);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, calls ? RingtoneManager.TYPE_RINGTONE : RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, current);
startActivityForResult(intent, calls ? 2 : 1);
return true;
}
@Override
protected void onClick() {
// Launch the ringtone picker
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
onPrepareRingtonePickerIntent(intent);
PreferenceFragment owningFragment = getPreferenceManager().getFragment();
if (owningFragment != null) {
owningFragment.startActivityForResult(intent, mRequestCode);
} else {
getPreferenceManager().getActivity().startActivityForResult(intent, mRequestCode);
}
}
@Subscribe
public void onBasicSettingsClicked(BasicSettingsClickEvent event)
{
if(event.getClickedSettingsObj()
.getKey()
.equals(ActivityMain.SETTINGS_KEY_RINGTONE))
{
String uriAsString = EasySettings.retrieveSettingsSharedPrefs(this)
.getString(ActivityMain.SETTINGS_KEY_RINGTONE,
SETTINGS_RINGTONE_SILENT_VALUE);
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true)
.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false)
.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION)
.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "");
if(uriAsString.equals(SETTINGS_RINGTONE_SILENT_VALUE))
{
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, 0);
}
else
{
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
Uri.parse(uriAsString));
}
startActivityForResult(intent, REQUEST_CODE_NOTIFICATION_PICKER);
}
else
{
makeToast(event.getClickedSettingsObj().getTitle());
}
}
private void showRingtonePicker() {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, onRestoreRingtone());
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, onRestoreRingtone());
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALL);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.pick_notification_ringtone));
this.startActivityForResult(intent, RINGTONE_REQUEST_CODE);
}
private void pickRingtone(int requestCode, Uri defaultSound) {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, App.getContext().getString(R.string.pick_audio));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, defaultSound);
if (getActivity() != null)
getActivity().startActivityForResult(intent, requestCode);
}
private void startRingtonePickerActivityForResult() {
Uri selectedRingtoneUri = Uri.parse(dialogContract.getRingtone());
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
getString(R.string.pref_ringtone_select_title));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, selectedRingtoneUri);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, selectedRingtoneUri);
startActivityForResult(intent, RINGTONE_INTENT_REQUEST_CODE);
}
@Override
public void onClick(View view) {
if (isAdded()) {
if (adapter.isRowChecked(view)) {
// open ringtone picker dialog
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.Ringtone_picker));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, getRingtoneUri(requestCode));
startActivityForResult(intent, requestCode);
}
} else {
adapter.setRowChecked(view, false);
}
}
@Override
public void onClick(View v) {
RingtoneSetting entry = getEntry();
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, entry.mValue);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, entry.mName);
intent.putExtra("android.intent.extra.ringtone.AUDIO_ATTRIBUTES_FLAGS", 0x1 << 6); // Perhaps a bit of a hack, but imo needed
mAdapter.startActivityForResult(intent, entry.mRequestCode);
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen prefScreen, Preference pref) {
if (pref == mNotifSoundPref) {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, mSoundUri);
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);
startActivityForResult(intent, REQ_PICK_SOUND);
return true;
}
return super.onPreferenceTreeClick(prefScreen, pref);
}
private void requestRingtone(String tag) {
if (!mSettingsHelper.getBoolean(tag + "_ringtone_enable", false))
return;
int request_code = -1;
switch (tag) {
case "custom":
request_code = REQUEST_TONE_PICKER_CUSTOM;
break;
case "new_comment":
request_code = REQUEST_TONE_PICKER_NEW_COMMENT;
break;
case "msg_recall":
request_code = REQUEST_TONE_PICKER_MSG_RECALL;
break;
case "comment_recall":
request_code = REQUEST_TONE_PICKER_COMMENT_RECALL;
}
if (request_code == -1)
return;
String uri = mSettingsHelper.getString(tag + "_ringtone", "");
final Uri currentTone = TextUtils.isEmpty(uri) ? RingtoneManager
.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION) :
Uri.parse(uri);
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.ringtone_selection));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentTone);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
startActivityForResult(intent, request_code);
}
@Override
protected void onClick() {
// Launch the ringtone picker
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
onPrepareRingtonePickerIntent(intent);
PreferenceFragment owningFragment = getPreferenceManager().getFragment();
if (owningFragment != null) {
owningFragment.startActivityForResult(intent, mRequestCode);
}/* else {
getPreferenceManager().getActivity().startActivityForResult(intent, mRequestCode);
}*/
}
@Override
public void onRingStone(int source) {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.ring_tone));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(Preferences.getRingtone(this, address, Preferences.Source.values()[source].name())));
startActivityForResult(intent, source);
}
@SuppressWarnings("deprecation")
@Override
public void onClick(View v) {
boolean status = false;
switch(v.getId()){
case R.id.antiTheftStatus:
status = MyUtils.getToogleImageStatus(ivShowAntiTheftStatus)==true?false:true;
setSP.setAntiTheftShowStatus(status);
MyUtils.setToogleImageStatus(ivShowAntiTheftStatus, status);
break;
case R.id.ring:
status = MyUtils.getToogleImageStatus(ivRing)==true?false:true;
setSP.setAntiTheftRing(status);
MyUtils.setToogleImageStatus(ivRing, status);
break;
case R.id.vibrate:
status = MyUtils.getToogleImageStatus(ivVibrate)==true?false:true;
setSP.setAntiTheftVibrate(status);
MyUtils.setToogleImageStatus(ivVibrate, status);
break;
case R.id.delay:
listType = 0;
FavoriteCharacterDialogFragment.show(this, "报警延时", strDelayTimes);
break;
case R.id.ringtone:
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "设置报警铃音");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
startActivityForResult(intent, REQUEST_SELECT_ALARM_RINGTONE);
break;
case R.id.enhancedMode:
status = MyUtils.getToogleImageStatus(ivEnhancedMode)==true?false:true;
setSP.setAntiTheftOpenBTEnhancedMode(status);
MyUtils.setToogleImageStatus(ivEnhancedMode, status);
break;
case R.id.bt:
status = MyUtils.getToogleImageStatus(ivBTClosed)==true?false:true;
setSP.setAntiTheftBTClosedAlarm(status);
MyUtils.setToogleImageStatus(ivBTClosed, status);
break;
case R.id.sensivity:
listType = 1;
FavoriteCharacterDialogFragment.show(this, "静置报警灵敏度", strRestSensitivitys);
break;
}
}
@Override
protected void onClick() {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
onPrepareRingtonePickerIntent(intent);
mParent.startActivityForResult(intent, RINGTONE_PICKER_REQUEST);
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
Log.e("KCA", "onPreferenceTreeClick " + preference.getKey());
String key = preference.getKey();
if (!isActivitySet) return false;
if (PREF_OVERLAY_SETTING.equals(key)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
showObtainingPermissionOverlayWindow();
} else {
showToast(getActivity(), getStringWithLocale(R.string.sa_overlay_under_m), Toast.LENGTH_SHORT);
}
}
if (PREF_SCREEN_ADV_NETWORK.equals(key)) {
mCallback.onNestedPreferenceSelected(NestedPreferenceFragment.FRAGMENT_ADV_NETWORK);
return false;
}
if (PREF_KCA_NOTI_RINGTONE.equals(key)) {
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, DEFAULT_NOTIFICATION_URI);
String existingValue = sharedPref.getString(key, null);
if (existingValue != null) {
if (existingValue.length() == 0) {
// Select "Silent"
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
} else {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(existingValue));
}
} else {
// No ringtone has been selected, set to the default
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Settings.System.DEFAULT_NOTIFICATION_URI);
}
startActivityForResult(intent, REQUEST_ALERT_RINGTONE);
}
if (PREF_CHECK_UPDATE.equals(key)) {
checkRecentVersion();
}
return super.onPreferenceTreeClick(preference);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
{
Log.d("PreferencesActivity", "onSharedPreferenceChanged " + key);
if (key.equals(MessengerPreferences.PREFERENCE_THEME))
{
restart();
}
else if (key.equals(MessengerPreferences.PREFERENCE_APP_LANGUAGE))
{
String l = sharedPreferences.getString(key, "default");
KlyphLocale.setAppLocale(l);
restart();
}
else if (key.equals(MessengerPreferences.PREFERENCE_FB_LANGUAGE))
{
refreshFbLanguage();
}
else if (key.equals(MessengerPreferences.PREFERENCE_NOTIFICATIONS_RINGTONE))
{
if (MessengerPreferences.getNotificationRingtone().equals("ringtone"))
{
Intent ringtoneManager = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
// specifies what type of tone we want, in this case "ringtone", can be notification if you want
ringtoneManager.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
// gives the title of the RingtoneManager picker title
ringtoneManager.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.preference_notification_ringtone_chooser));
// returns true shows the rest of the songs on the device in the default location
ringtoneManager.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, true);
startActivityForResult(ringtoneManager, RINGTONE_CODE);
}
else if (MessengerPreferences.getNotificationRingtone().equals("song"))
{
Intent intent = new Intent();
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, getString(R.string.preference_notification_ringtone_chooser)), SONG_CODE);
}
else
{
MessengerPreferences.setNotificationRingtoneUri(null);
refreshRingtoneSummary();
}
}
}