Detecting Sms Incoming and Outgoing

Detecting SMS incoming and outgoing

This is a good tutorial on both sending and receiving sms messages: http://mobiforge.com/developing/story/sms-messaging-android .

For the incoming messages you can indeed configure a broadcastlistener for detection. *

Detecting outgoing messages is also possible (just altered this post since I dind't know this). from: http://www.mail-archive.com/android-developers@googlegroups.com/msg26420.html

ContentResolver contentResolver = context.getContentResolver();
contentResolver.registerContentObserver(Uri.parse("content://
sms"),true, myObserver);

Detecting incoming and outgoing sms?

I had an application about SMS and Call blocker but i never upload it to play store because of after Kitkat ,you cant block sms messages. If you wanna do that just dont. I am sharing the sms part only, you can modify it as you want.

<!-- Android Permissions in manifest -->
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />

<!-- Define receiver inside the application tag -->
<receiver android:name="catchPackage.SmsController" android:process=":hascode_process" android:label="@string/sms_receiver"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_DELIVER"/>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
<!-- Broadcast receiver java code -->

public void onReceive(Context context, Intent intent) {
this.context = context;
try{
Bundle bundle = intent.getExtras(); //---get the SMS message passed in---
SmsMessage[] msgs = null;
String msg_from = null;
String msg_body = null;
if (bundle != null){
try{

boolean delete= false;
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int k=0; k<msgs.length; k++){
msgs[k] = SmsMessage.createFromPdu((byte[])pdus[k]);
msg_from = msgs[k].getOriginatingAddress();
System.out.println(msg_from);
String msgBody = msgs[k].getMessageBody();
msg_body = msgBody;

}

}catch(Exception e){
System.out.println(e.getMessage());
}
}
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}

}

Android: Detect SMS Outgoing, Incorrect Count

I found a solution to my problem. SMSs and MMSs can be uniquely distinguished by their _id value.

Uri uriSMSURI = Uri.parse("content://sms");
Cursor cur = getContentResolver().query(uriSMSURI, null, null,
null, null);
cur.moveToNext();
String id = cur.getString(cur.getColumnIndex("_id"));

Intercepting Outgoing SMS

Incoming SMS

You can intercept an incoming sms thru sms listener using Broadcast receiver.You can modify the incoming sms or destroy it so that it does not reaches inbox.

Outgoing SMS

You can listen for outgoing sms by putting content observer over content://sms/out but you can not modify it with the native sms app.You can obviously modify the content of content://sms/out but it has no point.

Android: Is there any way to listen outgoing sms?

You will have to do something like this:

  1. Cache all messages's hash code on the phone
  2. Register an content observer for content://sms
  3. In onChange method of observer, enumrate all messages to check if it is in cache, if not, the message is sent out just now.

Good luck with your project :-)

Edit: md5 method
You can take the (arrival date + message) text to get a unique md5 output.

private String md5(String in) {
MessageDigest digest;
try {
digest = MessageDigest.getInstance("MD5");
digest.reset();
digest.update(in.getBytes());
byte[] a = digest.digest();
int len = a.length;
StringBuilder sb = new StringBuilder(len << 1);
for (int i = 0; i < len; i++) {
sb.append(Character.forDigit((a[i] & 0xf0) >> 4, 16));
sb.append(Character.forDigit(a[i] & 0x0f, 16));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) { e.printStackTrace(); }
return null;
}

How to know when the phone receives a message

This is a good tutorial on both sending and receiving sms messages: http://mobiforge.com/developing/story/sms-messaging-android .

For the incoming messages you can indeed configure a broadcastlistener for detection. *

Detecting outgoing messages is also possible: http://www.mail-archive.com/android-developers@googlegroups.com/msg26420.html

ContentResolver contentResolver = context.getContentResolver();
contentResolver.registerContentObserver(Uri.parse("content://
sms"),true, myObserver);

Is it possible to know when user send SMS?

Sure. You can use something called as a ContentObserver. See this thread for details:

Detecting SMS incoming and outgoing



Related Topics



Leave a reply



Submit