直接设置铃声:
// ringtongVal : 卡1 或者卡2
List<Integer> ringtongIntVals = getRingTongTypeArrayWithReflect();
ringtongVal[0] 、或者:ringtongVal[1]
RingtoneManager.setActualDefaultRingtoneUri(context, ringtongVal, uri);
获取卡几的方法:
/**
* @return
*/
private static List<Integer> getRingTongTypeArrayWithReflect() {
List<Integer> ringtongIntVals = new ArrayList<>();
//默认系统的卡1
ringtongIntVals.add(RingtoneManager.TYPE_RINGTONE);
ringtongIntVals.add(8);
try {
Class clazz = Class.forName("android.media.RingtoneManager");
Field[] fields1 = clazz.getFields();
for (Field field : fields1) {
field.setAccessible(true);
if (!TextUtils.isEmpty(field.getName()) && field.getName().startsWith("TYPE_RINGTONE") && !field.getName().equals("TYPE_RINGTONE")) {
Log.d("getRingTong2 find ", field.getName() + "=>" + field.get(clazz));
ringtongIntVals.add(Integer.valueOf(field.get(clazz).toString()));
}
Log.d("getRingTong2=>", field.getName() + "=>" + field.get(clazz));
}
} catch (Exception e) {
e.printStackTrace();
}
return ringtongIntVals;
}
网友评论