Android系统修改默认铃声

Andriod手机的铃声默认保存在system/media/audio/下面,有四个文件夹,分别是alarms,notifications,ringtones,ui。对应闹钟、通知、铃声、UI音效。root的手机可以直接替换修改相应目录下的文件来修改铃声。那这些声音是从哪里来的呢。由于需要修改默认的铃声,就读了一下源码,这里进行记录一下。

在源码中,这些文件保存在frameworks\base\data\sounds目录下面,通过修改相应的mk文件把这些声音文件放到手机的相应目录。手机启动后会调用媒体库对手机内外存储上的多媒体文件进行扫描,保存其URI到媒体库的数据库中。当设置铃声时,会调用媒体库的(mediaProvider)RingtonePickerActivity进行设置。这里铃声Uri保存在数据库中,通过媒体库扫描出来显示个列表供选择。默认铃声的URI保存在设置(Settings)的数据库中,在表system里面。

修改默认铃声

修改mk文件,ro.config.ringtone对应手机默认铃声,ro.config.alarm_alert对应闹钟默认闹铃,ro.config.notification_sound设置通知默认响铃。我这里修改的是/build/target/product/full_base.mk,编译的时候这些值会被编到  build.prop内。

PRODUCT_PROPERTY_OVERRIDES := \
    ro.config.ringtone=yami_style1.ogg \
    ro.config.alarm_alert=Alarm_Rooster_02.ogg \
    ro.config.notification_sound=yami_notification.ogg

在MediaScanner.java中读取并保存配置到设置里面。

private static final String DEFAULT_RINGTONE_PROPERTY_PREFIX = "ro.config.";

private void setDefaultRingtoneFileNames() {
        mDefaultRingtoneFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
                + Settings.System.RINGTONE);
        mDefaultNotificationFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
                + Settings.System.NOTIFICATION_SOUND);
        mDefaultAlarmAlertFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
                + Settings.System.ALARM_ALERT);
    }

...

if (TextUtils.isEmpty(mDefaultRingtoneFilename) ||
                                doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename)) {
                            needToSetSettings = true;
                        }

...

 if(needToSetSettings) {
                if (notifications) {
                    setSettingIfNotSet(Settings.System.NOTIFICATION_SOUND, tableUri, rowId);
                    mDefaultNotificationSet = true;
                } else if (ringtones) {
                    setSettingIfNotSet(Settings.System.RINGTONE, tableUri, rowId);
                    if (MSimTelephonyManager.getDefault().isMultiSimEnabled()) {
                        // Set the setting to the given URI for RINGTONE_2
                        setSettingIfNotSet(Settings.System.RINGTONE_2, tableUri, rowId);
                    }
                    mDefaultRingtoneSet = true;
                } else if (alarms) {
                    setSettingIfNotSet(Settings.System.ALARM_ALERT, tableUri, rowId);
                    mDefaultAlarmSet = true;
                }
            }
这里看到写入了数据库中。

转自:https://blog.csdn.net/androidfish/article/details/30742565

猜你喜欢

转载自blog.csdn.net/xiao5678yun/article/details/82776904