Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8382097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:51:19+00:00 2026-06-09T16:51:19+00:00

I am new to Android and Java. The following code is to send and

  • 0

I am new to Android and Java. The following code is to send and wait for receiving SMS. As the process may takes about 3 minutes, I need to have a progressDialog until SMS is received. Could you send me an applet to do this ?

package com.examples.TOLD;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.TextView;

public class Sms extends Activity {
/** Called when the activity is first created. */

static TextView smsReceive;

@Override
protected void onCreate(Bundle savedInstanceState) 
{       
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sms);

    Intent i = getIntent();
    // Receiving the Data
    String reg = i.getStringExtra("reg");
    String port = i.getStringExtra("port");

    String smsMessage = 
        "REG=" + reg + 
        "PORT=" + port;

    // Show SMS sent message on screen 
    TextView smsSend = (TextView) findViewById(R.id.smsSend);
    smsSend.setText(smsMessage);
    Log.i("smsSend",String.valueOf(smsSend.getText()));
    // Send SMS message
    SmsManager sm = SmsManager.getDefault();
    String number = "5556";
    sm.sendTextMessage(number, null, smsMessage, null, null);

    // Receive SMS message
    smsReceive = (TextView) findViewById(R.id.smsReceive);

}
public static void updateMessageBox(String msg)
{
    smsReceive.append(msg);
}    
}

Here is another class to receive SMS:

package com.examples.TOLD;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;


public class SmsReceiver extends BroadcastReceiver{

public void onReceive(Context context, Intent intent)
{
    Bundle bundle=intent.getExtras();

    Object[] messages=(Object[])bundle.get("pdus");
    SmsMessage[] sms = new SmsMessage[messages.length];

    for(int n=0;n<messages.length;n++){
        sms[n]=SmsMessage.createFromPdu((byte[]) messages[n]);
    }

    for(SmsMessage msg:sms){
        String num = msg.getOriginatingAddress();
        Log.i("SMS sender",num);
        if (num.equals("15555215556")) {
        Sms.updateMessageBox("\nFrom: " + msg.getOriginatingAddress() + 
                "\n" + "Message: " + msg.getMessageBody() + "\n");}           
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:51:20+00:00Added an answer on June 9, 2026 at 4:51 pm

    I think you can try to reconsider your approach. You can’t expect user will be waiting for up to 3 minutes for the SMS. So you code looks right (except the part of the static method cos I explain you later), but once your message is sent, I’d show a message that your app is waiting for the message, and when the message is received in the SmsReceiver, you can communicate with the Sms activity.

    But, you shouldn’t use that static method to update the content of the activity for several reasons (UI can’t be updated in background or most important when the SmsReceiver is fired SMS activity can even non exist). The right way would be sending an intent from the receiver. You can see a detailed step by step example in the pdf contained in this link in the section Receiving SMS messages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to android programming. Getting Following error. 04-07 14:49:05.452: ERROR/AndroidRuntime(1566): FATAL EXCEPTION: main java.lang.OutOfMemoryError
Im new to Android and Java development and am following the Tab Layout tutorial
I used following code in java class of android. Everything works except it wont
I got the following code inside my templateApp.java: package com.android.templateApp; import android.app.Activity; import android.os.Bundle;
Im very new to android/java and have been following a few youtube tutorials and
I am a little new to android/java. I am trying to pass JSON values
I am new to Android and Java programming. I have a class which implements
Firstly I am new to android and Java so this is a beginners question.
I am very new to Android development and Java. Have read around but I'm
First of all, I'm quite new to the Android and JAVA world (coming from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.