android 关闭来电铃声,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        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值