I am creating an SMS Application to send and receive SMS.
I am able to send SMS using the following code:
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null,message , pi, null);
I would like to receive SMS and put them in my own inbox. How do I create this inbox? I would like it to work the same way as a normal inbox.
Bundle bundle = intent.getExtras();
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < messages.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
Log.v("SMSFun","Body: " + messages[i].getDisplayMessageBody());
Log.v("SMSFun","Address: " + messages[i].getDisplayOriginatingAddress());
//If say we wanted to do something based on who sent it
if (messages[i].getDisplayOriginatingAddress().contains("5556")) {
// we could launch an activity and pass the data
Intent newintent = new Intent(ctx, SecretMessage.class);
newintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newintent.putExtra("address", messages[i].getDisplayOriginatingAddress());
newintent.putExtra("message", messages[i].getDisplayMessageBody());
ctx.startActivity(newintent);
}
}
How do I store incoming SMS in the inbox?
Is it possible in Android to listen to particular port number for SMS?
Step 1: Start the new Android project and wait until the project was built successful. Step 2: Click on the layouts and open activity_main. xml file and click on the split option on the top to see the code as well as the design part. Step 3: Use the tag <TextView> to add text and modify text in the layout.
A SMS API is well-defined software interface which enables code to send short messages via a SMS Gateway.
I don't think you can place sms in different inboxes and you don't listen to a port to get SMS you use a BroadcastReceiver
.
I would recommend you to go through the open source smspopup app to get a better idea of how things work for sms in general.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With