【问题标题】:override sms tone with built-in alarm clock tone in android用android中的内置闹钟铃声覆盖短信铃声
【发布时间】:2012-12-02 10:58:55
【问题描述】:

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

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

【问题讨论】:

    标签: android alarm


    【解决方案1】:

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

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

    这样做是您将在默认和android消息应用程序之前首先收到消息,然后您可以阅读该短信并将其标记为已读。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多