Note that there are some explanatory texts on larger screens.

plurals
  1. POmake progressdialog while waiting to receive SMS
    primarykey
    data
    text
    <p>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 ?</p> <pre><code>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); } } </code></pre> <p>Here is another class to receive SMS:</p> <pre><code>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&lt;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");} } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload