sir, please help me in my program. i plan to ring an alarm if the user receives a message with a keyword. how do i force the application to use an alarm (the type that is always used in alarm clock) even if it’s not set up by the user and use it instead of the tone used when receiving messages. Because when i try to run the program, i hear both notification tone when sms is received as well as the default ringtone. thanks in advance
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
The only thing you can do is keeping the priority of intent filter in manifest to maximum which is some thing like
What this will do is that you will recieve the message first before default and android message app and then you can read that sms and mark it as read.
This is basically what applications like gosms do.