How To Track The Messages In Android?
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 me. Sim
Solution 1:
This is easy to do with a broadcast Receiver write in your Manifest:
edit: seems only to work for SMS_RECEIVED see this thread
<receiverandroid:name=".SMSReceiver"android:enabled="true"><intent-filterandroid:priority="1000"><actionandroid:name="android.provider.Telephony.SMS_RECEIVED"/><actionandroid:name="android.provider.Telephony.SMS_SENT"/></intent-filter></receiver>
And the Permission:
<uses-permissionandroid:name="android.permission.RECEIVE_SMS" />
Then Create the Receiver llike:
publicclassSMSReceiverextendsBroadcastReceiver {
@Override
publicvoidonReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
//do something with the received sms
}elseif(intent.getAction().equals("android.provider.Telephony.SMS_SENT")){
//do something with the sended sms
}
}
}
To handle a incoming sms might look like:
Bundleextras= intent.getExtras();
Object[] pdus = (Object[]) extras.get("pdus");
for (Object pdu : pdus) {
SmsMessagemsg= SmsMessage.createFromPdu((byte[]) pdu);
Stringorigin= msg.getOriginatingAddress();
Stringbody= msg.getMessageBody();
....
}
If you want to prevent a sms to be pushed in the commen InBox, you can achieve this with:
abortBroadcast();
Solution 2:
Please do not call abortBroadcast() you will prevent other apps receiving the SMS_RECEIVED ordered broadcast. This is bad behavior this is not what android is about. I dont understand why google even lets developer abort broadcasts of system intents like SMS.
Post a Comment for "How To Track The Messages In Android?"