【问题标题】:Android ringtone preference - fetch dataAndroid铃声偏好 - 获取数据
【发布时间】:2011-01-21 16:53:34
【问题描述】:

我有铃声偏好。我怎样才能得到选择?我有以下类型的代码:

if(preferences.getString("ringtonePref", "n/a") != ??)
            {
                Toast.makeText(TutorialPref.this,   "Chosen ringtone: silent", Toast.LENGTH_LONG).show();
            }
            else if(preferences.getString("ringtonePref", "n/a") != "DEFAULT_RINGTONE_URI" )
            {
                Toast.makeText(TutorialPref.this,   "Chosen ringtone: + default", Toast.LENGTH_LONG).show();
            }

【问题讨论】:

    标签: android ringtone preference


    【解决方案1】:

    这是您将选择分配给通知实例的方式。

    String strRingtonePreference = preferences.getString("ringtonePref", "DEFAULT_RINGTONE_URI");
    notification.sound = Uri.parse(strRingtonePreference);
    

    通知在哪里:

    Notification notification = new Notification(icon, tickerText, time);
    

    您可以在这里找到更多信息:http://developer.android.com/reference/android/app/Notification.html

    【讨论】:

    • "DEFAULT_RINGTONE_URI" 不起作用。而是将null 作为该参数传递,如果SharedPreferences.getString 返回null,则调用RingtoneManager.getActualDefaultRingtoneUri 而不是Uri.parse
    • 当首选项返回 null 时,Settings.System.DEFAULT_NOTIFICATION_URI 也是一个很好的默认值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    • 2014-04-25
    • 2013-10-11
    相关资源
    最近更新 更多