Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a SMS Application in Android?

Tags:

android

sms

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?

like image 455
Sasitharan Avatar asked Sep 01 '10 08:09

Sasitharan


People also ask

How do you make a SMS app?

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.

What is SMS API in Android?

A SMS API is well-defined software interface which enables code to send short messages via a SMS Gateway.


1 Answers

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.

like image 126
Macarse Avatar answered Oct 06 '22 12:10

Macarse