ringtone picker is not working

情到浓时终转凉″ 提交于 2019-12-12 02:05:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!