//设置铃声
    public static void setRingtone(File rt, Context context) {
        
        
        
if (rt != null && context != null && rt.exists()) {
            
//先扫描文件, 添加到媒体库中
            scanForMedia(rt, context);
            
//再从媒体库中,搜索该文件, 修改添加到铃声列表
            Cursor c = context.getContentResolver().query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 
null
                    
"_data = ?"new String[]{rt.getAbsolutePath()}, null);
            
            
if (c.getCount() > 0) {
                c.moveToFirst();
                
int id = c.getInt(0);
                
//添加到铃声列表
                ContentValues values = new ContentValues();
                values.put(MediaStore.Audio.Media.IS_RINGTONE, 
true);
                context.getContentResolver().update(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 
                        values, 
"_id = ?"new String[] {id + ""});
                
                
//得到该铃声的Uri
                Uri ringtone = Uri.withAppendedPath(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id + "");
                
                
//设置为默认铃声
                RingtoneManager.setActualDefaultRingtoneUri(
                context,
                RingtoneManager.TYPE_RINGTONE,
                ringtone
                );
            }
            c.close();
        }
    }
}