1、权限
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
2、代码
public void setPhoneMusic()
{ //设置当前文件存放音乐为手机铃声
Intent intent = new
Intent(RingtoneManager.ACTION_RINGTONE_PICKER); //打开系统铃声设置
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_RINGTONE);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
"设置来电铃声"); //设置显示的标题
startActivityForResult(intent,
RINGTONE_PICKED); //跳转界面,显示铃声设置对话框
}
public void
onActivityResult(int requestCode,int resultCode,Intent data)
{ //界面跳转方法
super.onActivityResult(requestCode, resultCode,
data);
if(resultCode!=RESULT_OK)
{
return;
}
switch(requestCode)
{ //switch判断
case
RINGTONE_PICKED: //开启手机铃声
try
{
Uri
pickedUri=data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if(pickedUri!=null)
{
RingtoneManager.setActualDefaultRingtoneUri
( //设置铃声链接
Sample8_11_Activity.this,
RingtoneManager.TYPE_RINGTONE,
pickedUri
);
}
}
catch(Exception
e)
{
e.printStackTrace(); //异常处理
}
break;
}
}
}
原文:http://www.cnblogs.com/wdc224/p/3704406.html