如何检查短信是否真的发送? [英] How to check if SMS message is really sent?

查看:44
本文介绍了如何检查短信是否真的发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SmsManager 发送几条 SMS 消息,并在发送某些消息时显示进度.如何检查消息是否真的发送?

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?

我有这个:

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.

推荐答案

您需要实现广播接收器来处理 msg & 的Delivery Report"msg的错误报告".

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

有 2 种类型,一种是用于 msg 递送 &另一个是错误,如果发生任何错误(链接通用错误等).

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

参考此链接:Android短信发送报告意图

这篇关于如何检查短信是否真的发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆