在Android中使用内置闹钟音调覆盖sms音调

时间:2012-12-02 10:58:55

标签: android alarm

先生,请帮助我完成我的课程。我计划在用户收到带有关键字的消息时发出警报。我如何强制应用程序使用警报(闹钟中始终使用的类型),即使它不是由用户设置并使用它而不是接收消息时使用的音调。因为当我尝试运行程序时,我会在收到短信时听到通知音以及默认铃声。提前谢谢

for (SmsMessage msg : messages) {
        if (msg.getMessageBody().contains("alert")) {

            Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
             if(alert == null){
                 // alert is null, using backup
                 alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                 if(alert == null){ 
                     // alert backup is null, using 2nd backup
                     alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);               
                 }
             }
             Ringtone r = RingtoneManager.getRingtone(context.getApplicationContext(), alert);
             r.play();
                Toast.makeText(context.getApplicationContext(), "alarm started", Toast.LENGTH_LONG).show();

        }//end if
    }//end for

1 个答案:

答案 0 :(得分:1)

你唯一能做的就是将清单中的意图过滤器的优先级保持在最大值,这就像是

<receiver android:name="com.missed.reciever.SmsReceiver" >
            <intent-filter android:priority="2147483647" >

这样做的原因是你会在默认和安卓消息应用程序之前收到消息,然后你可以读取该短信并将其标记为已读。

这基本上就像gosms这样的应用程序。