问题
i'm using this lib android.v4.preference.fragment, having issue with ringtone preference, the below code works superb for ICS and below version phones, but it launches duplicate ringtone dialog for ICS and above phones, i.e it launches 2 ringtone preference dialogs.
ringtonepref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
// TODO Auto-generated method stub
{
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity());
String path = settings.getString("prefnotificationTone", "content://settings/system/notification_sound");
Uri uri = !TextUtils.isEmpty(path) ? Uri.parse(path) : null;
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
//intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALL);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
getActivity().startActivityForResult(intent, 1000);
}
return true;
}
i'm handling like this in activity result
case 1000:
if (resultCode == Activity.RESULT_OK)
{
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
Editor editor = settings.edit();
editor.putString("prefnotificationTone", uri == null ? "": uri.toString());
editor.commit();
}
else
{
}
break;
i tried another way to compare the devices i.e ICS and above launch the default one else allow custom intent, but for Jelly bean and other devices i'm not getting the event to OnPreferenceChangeListener
, now i'm confused any help.
Thanks
回答1:
This is actually a workflow bug on the library and there are more than workaround for it that you can find here.
来源:https://stackoverflow.com/questions/27970723/ringtone-picker-is-not-working