Android删除除自定义铃声后,来电铃声显示是一串数字

[DESCRIPTION]

1.设置--声音--手机铃声--添加铃声--自定义铃声--选择音乐文件为铃声
2.设置--声音--手机铃声--添加铃声--自定义铃声--进入Files音频--查看Ringtones列表,删除刚才设置的铃声

或者进入File Manager--Internal shared storage--Ringtones,删除刚才设置的铃声 

 

[SOLUTION]

 

 出现之前现象的原因是铃声不存在,加载的是apk的资源。如下修改可以将来电改成无声音,贵司也可以重新设置某个铃声,改成某个固定的铃声。

RingtoneManager.java

//add begin
  public static boolean isRingtoneExist(Context context, Uri uri) {
        if (uri == null) {
            Log.e(TAG, "Check ringtone exist with null uri!");
            return false;
        }
        boolean exist = false;
        try {
            AssetFileDescriptor fd = context.getContentResolver().openAssetFileDescriptor(uri, "r");
            if (fd == null) {
                exist = false;
            } else {
                fd.close();
                exist = true;
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            exist = false;
        } catch (IOException e) {
            e.printStackTrace();
            exist = true;
        }
        Log.d(TAG, uri + " is exist " + exist);
        return exist;
    }
}
//add end

 /vendor/mediatek/proprietary/packages/services/Telecomm/src/com/android/server/telecom/RingtoneFactory.java

 55    public Ringtone getRingtone(Call incomingCall) {
56        // Use the default ringtone of the work profile if the contact is a work profile contact.
57        Context userContext = isWorkContact(incomingCall) ?
58                getWorkProfileContextForUser(mCallsManager.getCurrentUserHandle()) :
59                getContextForUserHandle(mCallsManager.getCurrentUserHandle());
60        Uri ringtoneUri = incomingCall.getRingtone();
61        Ringtone ringtone = null;
62
63        if(ringtoneUri != null && userContext != null) {
64            // Ringtone URI is explicitly specified. First, try to create a Ringtone with that.
65            ringtone = RingtoneManager.getRingtone(userContext, ringtoneUri);
66        }
67        if(ringtone == null) {
68            // Contact didn't specify ringtone or custom Ringtone creation failed. Get default
69            // ringtone for user or profile.
70            Context contextToUse = hasDefaultRingtoneForUser(userContext) ? userContext : mContext;
71            Uri defaultRingtoneUri;
72            if (UserManager.get(contextToUse).isUserUnlocked(contextToUse.getUserId())) {
73                defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(contextToUse,
74                        RingtoneManager.TYPE_RINGTONE);
75            } else {
76                defaultRingtoneUri = Settings.System.DEFAULT_RINGTONE_URI;
77            }
//add begin
              if(!RingtoneManager.isRingtoneExist(contextToUse,defaultRingtoneUri)){
       RingtoneManager.setActualDefaultRingtoneUri(context,AudioManager.STREAM_RING,null);//可以设置希望的铃声
   defaultRingtoneUri=null;
    }
//add end  
78            if (defaultRingtoneUri == null) {
79                return null;
80            }
81            ringtone = RingtoneManager.getRingtone(contextToUse, defaultRingtoneUri);
82        }
83        if (ringtone != null) {
84            ringtone.setStreamType(AudioManager.STREAM_RING);
85        }

你可能感兴趣的:(android,Andoid,Audio)