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
答案 0 :(得分:1)
你唯一能做的就是将清单中的意图过滤器的优先级保持在最大值,这就像是
<receiver android:name="com.missed.reciever.SmsReceiver" >
<intent-filter android:priority="2147483647" >
这样做的原因是你会在默认和安卓消息应用程序之前收到消息,然后你可以读取该短信并将其标记为已读。
这基本上就像gosms这样的应用程序。