RingtonePreference getEntry 方法

发布于 2025-01-02 14:12:09 字数 512 浏览 2 评论 0原文

我想在我的首选项屏幕中的摘要标签中显示当前选择的值。

对于ListPreference,我在方法中使用了getEntry方法

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

,我的类是:

public class AlarmPropertiesActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener

对于EditTextPreference,我使用了getText方法

我尝试获取RingtonePreference的默认值,但我还没有找到任何获取方法。

有人帮助我吗?

BR科莱萨尔

I want to display current selected value in my preferences screen in summary label.

For ListPreference, I used getEntry method in

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

method, my class is:

public class AlarmPropertiesActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener

For EditTextPreference, I used getText method

I try get default value for RingtonePreference, but I have not found any get method for that.

Anybody help me?

BR Kolesar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

东北女汉子 2025-01-09 14:12:09

这个对我有用;-)

if (pref instanceof RingtonePreference) {

            Log.i("***", "RingtonePreference " + pref.getKey());
            final RingtonePreference ringPref = (RingtonePreference) pref;
            ringPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference,
                        Object newValue) {
                    Log.i("***", "Changed " + newValue.toString());
                    Ringtone ringtone = RingtoneManager.getRingtone(
                            SettingsActivity.this, Uri.parse((String) newValue));
                    ringPref.setSummary(ringtone.getTitle(SettingsActivity.this));
                    return true;
                }
            });
            String ringtonePath=pref.getSharedPreferences().getString(pref.getKey(), "defValue");
            Ringtone ringtone = RingtoneManager.getRingtone(
                    SettingsActivity.this, Uri.parse((String) ringtonePath));
            ringPref.setSummary(ringtone.getTitle(SettingsActivity.this));

        }

This one works for me ;-)

if (pref instanceof RingtonePreference) {

            Log.i("***", "RingtonePreference " + pref.getKey());
            final RingtonePreference ringPref = (RingtonePreference) pref;
            ringPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference,
                        Object newValue) {
                    Log.i("***", "Changed " + newValue.toString());
                    Ringtone ringtone = RingtoneManager.getRingtone(
                            SettingsActivity.this, Uri.parse((String) newValue));
                    ringPref.setSummary(ringtone.getTitle(SettingsActivity.this));
                    return true;
                }
            });
            String ringtonePath=pref.getSharedPreferences().getString(pref.getKey(), "defValue");
            Ringtone ringtone = RingtoneManager.getRingtone(
                    SettingsActivity.this, Uri.parse((String) ringtonePath));
            ringPref.setSummary(ringtone.getTitle(SettingsActivity.this));

        }
始终不够爱げ你 2025-01-09 14:12:09

我有同样的问题。尝试检查 SharedPreferences 值,但不幸的是 uri 导致类似于命名文件的 id。

private void updateSummary(Preference p, SharedPreferences sharedPrefs) {
    if (p instanceof ListPreference) {

        ListPreference listPref = (ListPreference) p;
        p.setSummary(listPref.getEntry());

    } else if (p instanceof RingtonePreference) {

        /* 
         * This is kind of a longshot, since we are not able to get the entry directly and
         * so we have to go the route via the shared preferences.
         */

        RingtonePreference ringPref = (RingtonePreference) p;
        String ringtoneKey = ringPref.getKey();
        String ringtonePath = sharedPrefs.getString(ringtoneKey, "");
        ringPref.setSummary(ringtonePath);

    }
}

路径是这样的: content://media/internal/audio/media/25

所以这不是合适的解决方案。但我注意到,例如 GoogleTalk 应用程序也不会显示所选的通知声音。
另一方面,GoogleMail 则显示了这一点。

I have the same problem. Tried to go over the SharedPreferences value, but unfortunately the uri leads to an id like named file.

private void updateSummary(Preference p, SharedPreferences sharedPrefs) {
    if (p instanceof ListPreference) {

        ListPreference listPref = (ListPreference) p;
        p.setSummary(listPref.getEntry());

    } else if (p instanceof RingtonePreference) {

        /* 
         * This is kind of a longshot, since we are not able to get the entry directly and
         * so we have to go the route via the shared preferences.
         */

        RingtonePreference ringPref = (RingtonePreference) p;
        String ringtoneKey = ringPref.getKey();
        String ringtonePath = sharedPrefs.getString(ringtoneKey, "");
        ringPref.setSummary(ringtonePath);

    }
}

The path is something like this: content://media/internal/audio/media/25

So this is no suitable solution. But I noticed, that for example the GoogleTalk app doesn't show the selected notification sound as well.
GoogleMail on the other hand shows it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文