Android收到后会自动发送短信

时间:2015-03-20 10:39:54

标签: android sms send

我正在开发一个应用程序,当您以前收到一条短信时,它会向网站发送短信。我的问题是,当我尝试从之前收到的短信发送几条短信...我需要制作一个循环来控制一个字符串数组(msisdn,texto)来检查我收到了多少短信,同时我发送了它们,一个一。有人能帮我吗?谢谢:))

public class GetSMSTask extends AsyncTask<Void, Void, Void> {

private Context mContext;

public GetSMSTask(Context context) {
    mContext = context;
}

private static final String SMSBROKER = "http://xx.xx.xx.xx:8080/smsbroker/{params}";


@Override
protected Void doInBackground(Void... arg0) {
    OutcomeSms os=new OutcomeSms();
    String texto = null;
    String msisdn = null;

    HashMap<String, List<String>> hash = new HashMap<String, List<String>>();
    List<String> list = new ArrayList<String>();




    try {
        org.apache.http.client.HttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet(SMSBROKER);

        HttpResponse response = client.execute(get);
        Log.w("PlaySMSBroker","postSingal Response: " + response.getStatusLine());

        os.sendSMSMessage(msisdn, texto, mContext);

        list.add(texto);
        hash.put(msisdn,list);

        List<String> listOfMessages = hash.get(msisdn);
        int numberOfMessages = listOfMessages.size();

        for (int i=1; i<numberOfMessages; i++){
            os.sendSMSMessage(msisdn, texto, mContext);         
        }


    } catch (UnsupportedEncodingException e) {
        Log.e("PlaySMSBroker", "UnsupportedEncodingException:" + e.getMessage());
    } catch (ClientProtocolException e) {
        Log.e("PlaySMSBroker", "ClientProtocolException:" + e.getMessage());
    } catch (IOException e) {
        Log.e("PlaySMSBroker", "IOException:" + e.getMessage());
    } catch (Exception e) {
        Log.e("PlaySMSBroker", "Exception" + e.getClass().toString());
    }
    return null;
}

}

1 个答案:

答案 0 :(得分:0)

使用HashMap替换您的数字和法术矩阵。

将电话号码用于hashmap键,并将字符串列表用于hasmap值。

HashMap<a, b> matrix = new HashMap<a, b>();

a =电话号码

b =已发送邮件列表

发送短信时,请在列表中添加条目。如果是第一个sms在hashmap中放置一个。

要查看您发送的短信数量,请按号码获取列表,并计算列表中的项目数。

示例:

//to insert
HashMap<String, List<String>> hash = new HashMap<String, List<String>>();
List<String> list = new ArrayList<String>();
list.add("message1");
hash.put("993739292",list);

//to get list by telefone number
List<String> listOfMessages = hash.get("993739292");
int numberOfMessages = listOfMessages.size();