Android更改通知铃声

时间:2012-10-09 14:07:02

标签: android

我想授权用户更改通知铃声。它“必须”通过app而不是'thro'设置。我试过以下代码。它显示铃声选择器,但“它没有设置选定的”。我知道它已经发布了很多时间。我做错了什么?

private void setRington() 
{
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    Uri soundFile = Uri.parse(settings.getString("timerSound", RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString()));

    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Alert Tone");
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, soundFile);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);     
    startActivityForResult(intent, 5);
}

@Override    
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{       
    if (resultCode == Activity.RESULT_OK && requestCode == 5) 
    {            
        Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); 
        Log.i("Speak", "I picked this ringtone " + uri);
        if (uri != null) 
        {    
            RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, uri);
        }
    } 
} 

0 个答案:

没有答案