0

I am creating a SMS app in Android. I want to encrypt the body of messages based on the address. But as soon as I receive any message. notificationbar shows the message body which obviously I dont want. Can somebody suggest me how to disable this and send my own notifications as soon as I receive any message.

EDIT:

    public void onReceive(final Context context, Intent intent) {
     if (intent.getAction().equals(SMS_RECEIVED)){

    Bundle extras = intent.getExtras();


    //StringBuilder text = new StringBuilder();

    if (extras != null) {
        abortBroadcast();
        // Get received SMS array
        final Object[] smsExtra = (Object[]) extras.get(SMS_EXTRA_NAME);
        // Get ContentResolver object for pushing encrypted SMS to incoming
        // folder

        final ContentResolver contentResolver = context.getContentResolver();
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

              public void run() {
                  String messages = "";
                  for (int i = 0; i < smsExtra.length; ++i) {
                        SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]);

                        final String body = sms.getMessageBody().toString();
                         String address = sms.getOriginatingAddress();
                     String body1 = null;
                    String number = null;
                    Log.i("MY_SMS_RECEIVER","body address and length of extras are "+body+" "+address+" "+String.valueOf(smsExtra.length));

                //Do something after 100ms
                  Cursor updateCursor = contentResolver.query(Uri.parse("content://sms/inbox"), new String[]{"address","body","_id","type"}, "address = ?", new String[]{address}, null);
                    Cursor c = contentResolver.query(Uri.parse("content://sms/inbox"), new String[]{"address","body","_id","type"}, "address = ?", new String[]{address}, null);

                    if(c.getCount()>0) 
                    {
                        while(c.moveToNext()){
                            Log.i("ids in inbox content is ",String.valueOf(c.getLong(c.getColumnIndexOrThrow("_id"))));
                        }
                    }
                    c.close();
                    AddressDBHandler dba = new AddressDBHandler(context);
                    ContentValues val = new ContentValues();
                    if(dba.alreadyExisted(address)){
                        if(updateCursor.moveToFirst())
                        {
                             body1= updateCursor.getString(updateCursor.getColumnIndexOrThrow("body")).toString();
                               number = updateCursor.getString(updateCursor.getColumnIndexOrThrow("address")).toString();
                               Long id  = updateCursor.getLong(updateCursor.getColumnIndexOrThrow("_id"));
                               Log.i("MY_SMS_RECEIVER", "frist received message body and address and id is "+body1+" "+number+" "+id.toString());

                            do
                            {
                                String status = "E";
                                id  = updateCursor.getLong(updateCursor.getColumnIndexOrThrow("_id"));
                                EndecDBHandler db = new EndecDBHandler(context);
                                EndecDB  endec = new EndecDB(id.intValue(),status);


                                try {

                                    if(!db.alreadyExisted(endec)){
                                db.insertEncryptedData(endec);
                                Log.i("MY_SMS_RECEIVER","succeeded to insert");

                                val.put("body", SimpleCrypto.encrypt("smstrove", body1));
                                contentResolver.update(
                                        Uri.parse("content://sms/inbox"), val,
                                        "address = ? and body = ?", new String[] { address,body1 });
                                Log.i("MY_SMS_RECEIVER","both databases has been updated");}
                                    }
                                catch(Exception e)
                                {
                                    Log.i("MY_SMS_RECEIVER","could not able to insert");
                                }
                            } while(updateCursor.moveToNext());
                        }
                        updateCursor.close();

                    }
                    messages += "SMS from " + address + " :\n";
                    messages += body + "\n";

                    //putSmsToDatabase(contentResolver, sms, body,context);
                  }
              }
            }, 3000);



        }
    else
        abortBroadcast();

        // Display SMS message
    //  Toast.makeText(context, messages, Toast.LENGTH_LONG).show();


    }
}

I am putting delay of 3 secs as content://sms/inbox need time to get update and then sending the message to database that store encrypted addresses. The problem is when I abort the broadcast after getting the data from the intent, content://sms/inbox doesnot updated with the new message and I am unable to show the message to the user.

aneela
  • 1,457
  • 3
  • 24
  • 45

1 Answers1

0

Have a look at this one. Intercepting Message Notifications in Android

Rajeev N B
  • 1,365
  • 2
  • 12
  • 24
  • I dont know whats the problem but when I use `abortBroadcast()` my own sms app is not able to show the new message. I guess its the problem with the `content://sms/inbox` which need sometime to get updated... and when I gave it sometime, the broadcast reaches to the native app and `notificationbar` showed the message content. – aneela Dec 19 '12 at 05:51