Android 如何设置视频来电的默认铃声

前言
         欢迎大家我分享和推荐好用的代码段~~
声明
         欢迎转载,但请保留文章原始出处:
         CSDN
http://www.csdn.net
         雨季o莫忧离:http://blog.csdn.net/luckkof

正文

 

背景:
原始设计语音来电铃声和视频来电铃声是一起设置的。即设置的默认铃声同时是语音来电和视频来电的铃声。
 
需求:
只想单独设置视频来电的默认铃声。
 
实现思路:
参考原先来电铃声的设置机制,给视频来电铃声单独设置属性写默认的铃声名称,然后在文件扫描时,判断扫描到的文件是设置的默认视频铃声的文件名,则在database中填写视频来电的键值为此铃声;
 
PS:被设置的铃声首先要存在于系统中,关于如何添加系统铃声请参考”FAQ06323[Audio Profile]如何添加以及删减特定的默认通知铃声,如何设置默认铃声
 
1,添加Video Call默认铃声的属性:
alps\build\target\product\core.mk中添加“ro.config.video_call”:

PRODUCT_PROPERTY_OVERRIDES := \
    ro.config.notification_sound=Proxima.ogg \
    ro.config.alarm_alert=Alarm_Classic.ogg \
    ro.config.ringtone=Backroad.ogg \
    ro.config.video_call=VideocallRt.ogg

 
2,添加对扫描到文件的判断是否是默认Vide Call的默认铃声:
alps\frameworks\base\media\java\android\media\mediascanner.java:

1),添加成员变量用做后面的判断:
private String mDefaultRingtoneFilename;
private String mDefaultVideocallFilename;
private boolean mDefaultRingtoneSet;
private boolean mDefaultVideoCallSet;
private static final String RINGTONE_SET = "ringtone_set";
private static final String VIDEOCALL_SET = "videocall_set";

2):添加读取video call默认铃声的系统属性:
private void setDefaultRingtoneFileNames() {
        mDefaultRingtoneFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
                + Settings.System.RINGTONE);
        mDefaultVideocallFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
                + Settings.System.VIDEO_CALL);//add this line
...
    }
 
3):添加对扫描到的文件是否是视频来电默认铃声的判断:
参考标有//start modify”和//end modify”中间包含的为添加整段code,"//add this line"和”Modify this line"为添加添加的语句和修改的语句。
并请留意“else if (ringtones && doesSettingEmpty(RINGTONE_SET)&&!videocall) {”中要一定注释掉对VideoCall的设置:

private Uri endFile(){
       boolean videocall = false; //add this line
.....
 if (notifications &&((mWasEmptyPriorToScan && !mDefaultNotificationSet) ||
                        doesSettingEmpty(NOTIFICATION_SET))) {
                                ....   
//start modify
} else if(ringtones && ((mWasEmptyPriorToScan && (!mDefaultRingtoneSet||!mDefaultVideoCallSet)) || doesSettingEmpty(RINGTONE_SET)|| doesSettingEmpty(VIDEOCALL_SET))) {
                    if (TextUtils.isEmpty(mDefaultRingtoneFilename) ||
                            doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename)) {
                        needToSetSettings = true;
                        /// M: Adds log to debug setting ringtones.
                        Xlog.v(TAG, "endFile: needToSetRingtone=true.");
                    }
                    if (TextUtils.isEmpty(mDefaultVideocallFilename) ||
                            doesPathHaveFilename(entry.mPath, mDefaultVideocallFilename)) {
                        needToSetSettings = true;
                        videocall = true;
                        /// M: Adds log to debug setting ringtones.
                        Xlog.v(TAG, "endFile: needToSetRingtone=true.");
                    }

                }
 else if (alarms && ((mWasEmptyPriorToScan && !mDefaultAlarmSet) ||
                        doesSettingEmpty(ALARM_SET))) {
                      ...                   
}
 
...
if(needToSetSettings) {
                if (notifications && doesSettingEmpty(NOTIFICATION_SET)) {
                  .....
//start modify
                } else if (ringtones && (doesSettingEmpty(RINGTONE_SET)||doesSettingEmpty(VIDEOCALL_SET)) {
                    if(videocall){
                     setSettingIfNotSet(Settings.System.VIDEO_CALL, tableUri, rowId);
                    setProfileSettings(RingtoneManager.TYPE_VIDEO_CALL, tableUri, rowId);
                    mDefaultVideoCallSet = true;
                    setSettingFlag(VIDEOCALL_SET);
                    }
                    else{
                    setSettingIfNotSet(Settings.System.RINGTONE, tableUri, rowId);
                   // setSettingIfNotSet(Settings.System.VIDEO_CALL, tableUri, rowId); //modify this line
                    setSettingIfNotSet(Settings.System.SIP_CALL, tableUri, rowId);
                    setProfileSettings(RingtoneManager.TYPE_RINGTONE, tableUri, rowId);
                   // setProfileSettings(RingtoneManager.TYPE_VIDEO_CALL, tableUri, rowId);//modify this line
                    setProfileSettings(RingtoneManager.TYPE_SIP_CALL, tableUri, rowId);
                    mDefaultRingtoneSet = true;
                    setSettingFlag(RINGTONE_SET);
                    }

                    Xlog.v(TAG, "endFile: set ringtone. uri=" + tableUri + ", rowId=" + rowId);
                 //end modify
                }else if (alarms && doesSettingEmpty(ALARM_SET)) {
                   ....
            }
 

Android 如何设置视频来电的默认铃声

上一篇:【安卓笔记】安卓下xml文件的解析


下一篇:Android [2G/FDD]关闭GSM四频和HSPA方法