使用broadcastreceiver更改短信通知声音

时间:2018-01-20 10:27:33

标签: android notifications sms

我正在使用广播接收器来获取新收到的短信并检查它是否包含一个单词以使用我的SD卡中的另一个声音来更改移动短信通知声音 怎么做 这是我的代码

if (intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)){


        final Bundle bundle = intent.getExtras();
        try {
            if (bundle != null) {
                final Object[] pdusObj = (Object[]) bundle.get("pdus");
                for (int i = 0; i < pdusObj.length; i++) {
                    SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                    String address = currentMessage.getDisplayOriginatingAddress();

                    String smsBody = currentMessage.getDisplayMessageBody();

if (smsBody.contains("hello")){


//there i need to change notification sound and mute the base mobile notification and use another sound from sdcard


}

1 个答案:

答案 0 :(得分:0)

尝试:

RingtoneManager.setActualDefaultRingtoneUri(this,RingtoneManager.TYPE_NOTIFICATION,uriOfAudioFile);