Android 收到短信后自动发送

Android Send SMS automatically when it is received

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

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;
}

}

使用 HashMap 替换您的数字矩阵和菜单。

使用电话号码作为 hashmap 键,使用字符串列表作为 hasmap 值。

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

a = 电话号码

b = 已发送消息列表

发送短信时,在列表中添加一个条目。如果它是第一条短信,请将其放入哈希图中。

要查看您发送了多少条短信,请按编号获取列表并统计您在列表中有多少项。

示例:

//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();