0

I am working on Android application about SMS.I need some suggestion from the master. Now i am trying to read sms with this code block :

private String readSMS(){
        Uri SmsUri=Uri.parse("content://sms/inbox");
        String[] projection=new String[]{"_id","address","body","date"};
        Cursor cursor=null;
        cursor=getContentResolver().query(SmsUri,projection,null,null,null);
        if(cursor!=null&&cursor.moveToFirst()){    
            int id=cursor.getInt(cursor.getColumnIndex("_id"));    
            String address=cursor.getString(cursor.getColumnIndex("address")); 
            String body=cursor.getString(cursor.getColumnIndex("body")); 
            return body;     
        }       
        return "";
    }

Now I want to ask a question. Can i write a layer to manage SMS. For example i want to read SMS before user recognize it. I will use this sms if i want and show in my program else i will do nothing and Orginal phone SMS app will take it and report user by a notification. This is what i mean : enter image description here

Thank you.

Bahadır Yılmaz
  • 368
  • 1
  • 4
  • 23

1 Answers1

0

You could implement a BroadcastReceiver that catches messages and processes them as you need it. See this post on how to implement it.

In order to cancel further processing of a message by other apps call abortBroadcast();as per this post. It's important to set the priority to a rather high value, though you are advised to not use the maximum.

Hope this helps .... Cheers!

Community
  • 1
  • 1
Trinimon
  • 13,839
  • 9
  • 44
  • 60