把sd卡中的mp3设置为闹铃或来电提示音

public static void setMyAlarm(Context paramContext, String paramString)
{
    File localFile = new File(paramString);
    ContentValues localContentValues = new ContentValues();
    localContentValues.put( MediaStore.MediaColumns.DATA, localFile.getAbsolutePath());
    localContentValues.put(MediaStore.MediaColumns.TITLE, localFile.getName());
    localContentValues.put(MediaStore.MediaColumns.SIZE, Long.valueOf(localFile.length()));
    localContentValues.put(MediaStore.Audio.Media.IS_RINGTONE, Boolean.valueOf(false));
    localContentValues.put(MediaStore.Audio.Media.IS_NOTIFICATION, Boolean.valueOf(false));
    localContentValues.put(MediaStore.Audio.Media.IS_ALARM, Boolean.valueOf(true));
    localContentValues.put(MediaStore.Audio.Media.IS_MUSIC, Boolean.valueOf(false));
    Uri localUri = MediaStore.Audio.Media.getContentUriForPath(paramString);
    RingtoneManager.setActualDefaultRingtoneUri(paramContext, RingtoneManager.TYPE_ALARM, paramContext.getContentResolver().insert(localUri, localContentValues));

}

public static void setMyRing(Context paramContext, String paramString)
{
    File localFile = new File(paramString);
    ContentValues localContentValues = new ContentValues();
    localContentValues.put( MediaStore.MediaColumns.DATA, localFile.getAbsolutePath());
    localContentValues.put(MediaStore.MediaColumns.TITLE, localFile.getName());
    localContentValues.put(MediaStore.Audio.Media.IS_RINGTONE, Boolean.valueOf(true));
    Uri localUri = MediaStore.Audio.Media.getContentUriForPath(localFile.getAbsolutePath());
    paramContext.getContentResolver().delete(localUri, "_data=\"" + localFile.getAbsolutePath() + "\"", null);
    RingtoneManager.setActualDefaultRingtoneUri(paramContext, RingtoneManager.TYPE_RINGTONE, paramContext.getContentResolver().insert(localUri, localContentValues));
}
//短信出错 设置不成功 不知道原因

public static void setMyMessage(Context paramContext, String paramString)
{
    File localFile = new File(paramString);
    ContentValues localContentValues = new ContentValues();
    localContentValues.put( MediaStore.MediaColumns.DATA, localFile.getAbsolutePath());
    localContentValues.put(MediaStore.MediaColumns.TITLE, localFile.getName());
    localContentValues.put(MediaStore.MediaColumns.SIZE, Long.valueOf(localFile.length()));
    localContentValues.put(MediaStore.Audio.Media.IS_RINGTONE, Boolean.valueOf(false));
    localContentValues.put(MediaStore.Audio.Media.IS_NOTIFICATION, Boolean.valueOf(true));
    localContentValues.put(MediaStore.Audio.Media.IS_ALARM, Boolean.valueOf(false));
    localContentValues.put(MediaStore.Audio.Media.IS_MUSIC, Boolean.valueOf(false));
    Uri localUri = MediaStore.Audio.Media.getContentUriForPath(paramString);
    RingtoneManager.setActualDefaultRingtoneUri(paramContext, RingtoneManager.TYPE_NOTIFICATION, paramContext.getContentResolver().insert(localUri, localContentValues));
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值