2011-10-03 120 views
5

我有這個在我的preferences.xml偏好鈴聲默認值

 <RingtonePreference android:key="ringtone_uri" 
      android:title="@string/preferences_select_ringtone" 
      android:showDefault="true" android:srinlent="true" 
      android:summary="@string/preferences_select_ringtone_summary" /> 

而且每次當我第一次開始全新安裝的應用程序,在無聲:(默認值,當我在鈴聲偏好挖掘時間我怎樣才能做到這一點 enter image description here

我如何設置默認值爲「默認鈴聲」不沉默,我默認情況下,默認值爲「默認鈴聲」不知道爲什麼這是沉默的,因爲我的默認設置沒有設置在我的代碼中的任何地方,沉默是Android系統的默認設置...

回答

5

我正在搜索如何設置鈴聲的默認值,並意識到,當沒有設置首選項時,該值爲空且無聲被選爲默認值。但我這樣做

defaultstr = Uri.parse(PreferenceManager.getDefaultSharedPreferences(context).getString("r_uri", 
    android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString())); 
//than I do this, I save the default ringtone to my setting 
if (defaultstr.equals(android.provider.Settings.System.DEFAULT_RINGTONE_URI)) { 
    PreferenceManager.getDefaultSharedPreferences(context).edit().putString("r_uri", 
     android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString()).commit(); 
} 

我希望這會幫助別人。順便說一句我嚇壞了找到這個解決辦法,我是漿紗我的頭幾個小時

1

只是禁用「靜音」項目:

<RingtonePreference android:key="ringtone_uri" 
      android:title="@string/preferences_select_ringtone" 
      android:showDefault="true" android:srinlent="true" 
      android:summary="@string/preferences_select_ringtone_summary" 
      android:showSilent="false"> 
+0

這可能會起作用,但只限於您不想讓用戶選擇無聲鈴聲。 – nstCactus

6

設置默認值默認鈴聲

<RingtonePreference 
     android:showDefault="true" 
     android:showSilent="true" 
     android:defaultValue="content://settings/system/notification_sound" 
        ....... 
     > 
</RingtonePreference> 
最簡單的方法