android日历应用内默认铃声和实际听到的铃声不一致问题
程序员文章站
2022-04-12 09:16:13
1.首先在类frameworks/base/media/java/android/media/MediaPlayer.java的setDataSource方法内对当前播放的uri进行打log,打了log之后就知道了当前播放的uri(与默认铃声不符的铃声uri),添加判断uri为当前播放的uri的话,就将默认铃声设置进去 public void setDataSource(@NonNull Context context, @NonNull Uri uri) throws .....
1.首先在类 frameworks/base/media/java/android/media/MediaPlayer.java 的setDataSource方法内对当前播放的uri进行打log,打了log之后就知道了当前播放的uri(与默认铃声不符的铃声uri),添加判断uri为当前播放的uri的话,就将默认铃声设置进去
public void setDataSource(@NonNull Context context, @NonNull Uri uri)
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
//add start
String str = uri.toString();
if (str.equals("android.resource://com.google.android.calendar/raw/timely_event") ) {
Uri muri = RingtoneManager.getActualDefaultRingtoneUri(context,RingtoneManager.TYPE_NOTIFICATION);
setDataSource(context, muri, null, null);
} else {
setDataSource(context, uri, null, null);
}
//add end
}
2.还要在vendor/mediatek/proprietary/packages/providers/MediaProvider/src/com/android/providers/media/RingtonePickerActivity.java 内的onPrepareListView()方法内添加
//add start
String str = mExistingUri.toString();
if (str.equals("android.resource://com.google.android.calendar/raw/timely_event")) {
int mClickedPos = getListPosition(mRingtoneManager.getRingtonePosition(
RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(),mType)));
setCheckedItem(mClickedPos);
}
//add end
注:文中出现的:android.resource://com.google.android.calendar/raw/timely_event 是我打log和默认铃声不对的资源,你们要打将uri打log,在铃声响的时候看log里面是那个,再将log打出来的uri替换掉android.resource://com.google.android.calendar/raw/timely_event的位置,才能实现出现的铃声就是默认铃声的效果
本文地址:https://blog.csdn.net/qq_18273521/article/details/107409510
上一篇: HTML5学习笔记