0

I am creating an application for android OS, which allows user to send encrypted SMS to other users. But my application has only interface for sending an SMS, not for showing it. When application receives an SMS, I wan't to decrypt it and then somehow to show the decrypted SMS through the bult-in SMS Application. Is there a way to accomplish that? For now my receiver just shows the SMS using Toast. Here is Receiver's code (It is not full but you will get the idea):

public class SMSReceiver extends BroadcastReceiver{
private static final byte HANDSHAKE_ID = (byte) 120;
private static final byte ENCRYPTED_ID = (byte) 125;

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Bundle pudsBundle = intent.getExtras();
    Object[] pdus = (Object[]) pudsBundle.get("pdus");
    SmsMessage messages = SmsMessage.createFromPdu((byte[]) pdus[0]);

    Log.i("Message: ",  messages.getMessageBody());

    String msgBody = messages.getDisplayMessageBody();
    byte[] msgBytes = msgBody.getBytes();

    if ( msgBytes[0] == HANDSHAKE_ID ) {
        //Obtain secret key from message
        //TO-DO

        Toast.makeText(context, "Received a secret key from: " + messages.getOriginatingAddress(), Toast.LENGTH_LONG).show();

    } else if ( msgBytes[0] == ENCRYPTED_ID ) {
        //Obtain encrypted message
        //TO-DO

        Toast.makeText(context, plainText, Toast.LENGTH_LONG).show();
    }

 }

Also if it is possible I want to prevent other Apps to see(receive) the message if first byte of the message is one of following constants: HANDSHAKE_ID or ENCRYPTED_ID and visible after decryption? But the main problem that I wan't to solve is how to show plaintext with Android's Built-In SMS Application. Thanks!

M.Veli
  • 519
  • 1
  • 6
  • 15
  • 1
    If you want to send binary data via SMS, look into port based SMS instead of the standard text SMSes. Port based SMS act more like sockets, allowing it to be sent to a single listener app rather than to the phone's SMS system. That solves the hanshake/encryption id problem. – Gabe Sechan Jun 25 '14 at 19:49
  • 1
    As for showing in the default SMS app- it used to be possible, you could write to the SMS database. As of Android 4.4 (KitKat) this is no longer allowed for any app except the default SMS Provider. So I'm not sure if there's a way to do it anymore. – Gabe Sechan Jun 25 '14 at 19:53
  • Yes, I have tested now Port-based SMS, and thats what I need, thank you Gabe. But the problem with showing (visualising) the SMS after receiving it is still persist. At least I want to show a notification after receiving an SMS, and if the user clicks on it to show an Activity which contains received SMS. – M.Veli Jun 26 '14 at 13:35

0 Answers0