2

I am trying to send a couple of SMS messages with SmsManager and display progress when some of the messages are sent. How can I check if message is really sent?

I have this:

private class SomeAsyncTask extends
            AsyncTask<ArrayList<Person>, Integer, Void> {
        private ProgressDialog dialog;
        private Context context;

        public SomeAsyncTask(Activity activity) {
            context = activity;
            dialog = new ProgressDialog(context);
            dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        }

        protected void onPreExecute() {
            this.dialog.setMessage("Processing!");
            this.dialog.show();
        }

        @Override
        protected Void doInBackground(ArrayList<Person>... params) {
            dialog.setMax(params[0].size());

            for (int i = 0; i < params[0].size(); i++) {
                SmsManager.getDefault().sendTextMessage(params[0].get(i).getNum(), null, "test", null, null);
                publishProgress((int) ((i / (float) params[0].size()) * 100));

            }

        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);
            dialog.setProgress(values[0]);
        }

        @Override
        protected void onPostExecute(Void v) {
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
        }
    }

After each successfully sent message I want to update progress. What do you recommend me to do? Thank you.

user3339562
  • 1,325
  • 4
  • 18
  • 34
  • 1
    Take a look at my answer to this question: http://stackoverflow.com/questions/19083158/send-sms-until-it-is-successful this way you receive a broadcast when the SMS has been send and another when it has been delivered, in case you want to know that aswell – cYrixmorten Jul 23 '14 at 03:28
  • @cYrixmorten, Thank you. It is really helpful! Now I am wondering how can I report progress to my ProgressDialog when message is sent? – user3339562 Jul 24 '14 at 17:13
  • No problem :) I think the simplest way would be to create and register the broadcast receiver within your Activity as a private class. This way you would be able to, say, have the dialog as a public field and update the progress directly from within the receiver. – cYrixmorten Jul 25 '14 at 23:46

1 Answers1

1

You need to implement broadcast receiver to handle "Delivery Report" of msg & "Error Report" of msg.

There are 2 types one is for msg delivery & another is for error, if any error is occured (linke generic error etc).

Refer this link : Android SMS Message delivery report intent

Community
  • 1
  • 1
VVB
  • 7,363
  • 7
  • 49
  • 83