2015-09-11 146 views

回答

0

端起來只是把RingtonePreference的子類,覆蓋onPrepareRingtonePickerIntent方法始終提供默認的通知音RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,非常微小的變化,所以希望它是安全的。這是我的班級:

package com.myexample; 

import android.content.Context; 
import android.content.Intent; 
import android.media.RingtoneManager; 
import android.preference.RingtonePreference; 
import android.util.AttributeSet; 

public class MyRingtonePreference extends RingtonePreference { 
    public MyRingtonePreference(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

    public MyRingtonePreference(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public MyRingtonePreference(Context context) { 
     super(context); 
    } 

    protected void onPrepareRingtonePickerIntent(Intent ringtonePickerIntent) { 

     ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, 
       onRestoreRingtone()); 

     ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, getShowDefault()); 
     if (getShowDefault()) { 
      ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, 
        RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); 
     } 

     ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, getShowSilent()); 
     ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, getRingtoneType()); 
     ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getTitle()); 
    } 
}