I want to develop an app which tracks the sent/received SMSs. I mean, when a user sends a message from its device, the message detail should be saved to a table provided by
This is easy to do with a broadcast Receiver write in your Manifest:
edit: seems only to work for SMS_RECEIVED see this thread
And the Permission:
Then Create the Receiver llike:
public class SMSReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
//do something with the received sms
}else if(intent.getAction().equals("android.provider.Telephony.SMS_SENT")){
//do something with the sended sms
}
}
}
To handle a incoming sms might look like:
Bundle extras = intent.getExtras();
Object[] pdus = (Object[]) extras.get("pdus");
for (Object pdu : pdus) {
SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdu);
String origin = msg.getOriginatingAddress();
String body = msg.getMessageBody();
....
}
If you want to prevent a sms to be pushed in the commen InBox, you can achieve this with:
abortBroadcast();