Vous êtes sur la page 1sur 2

2 down vote favorite OK. I am sending text messages through my app.

After a text message is sent, it sends a status update to a server. This portion works okay, but the problem I am running into is twofold. I am not sure if they are related, but I assume that t hey are. My app has the ability to send a single text to multiple users. Here is a sample of the code... if(phoneNumbers.length > 0 && message.getText().toString().equals("") == false) { for(int i=0;i<phoneNumbers.length;i++) { sms = SmsManager.getDefault(); try { sms.sendTextMessage(phoneNumbers[i], null, message.getText().toStrin g(), null, null); sentQuantity++; } catch(IllegalArgumentException e) { } } } Basically, it just loops through an array of phone numbers, and sends the text o ne at a time. Here is where part of my issue lies. If I choose 3 or more numbers to send the text to, sometimes not all of the texts actually get sent. It happe ns very randomly. I assume it is because there is a delay between sending each individual message, but the code doesn't wait long enough. I reached this assumption because if I s tep into the program using eclipse and manually go through the app, everything a lways works just fine. My other issue is when I send off the text message status update to a web server . Immediately after the text messages get sent, the app then connects to the inter net and tells the server via an http post the number of texts that were sent. He re is my snippet of internet code... for(int i = 0; i < postNames.length; i++) { nameValuePairs.add(new BasicNameValuePair(postNames[i], postValues[i])); } //http post try{ HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 10000; HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConn ection );

HttpClient httpclient = new DefaultHttpClient(httpParameters); HttpPost httppost = new HttpPost(webAddress); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); This section just compiles the items for the post, connects to a web page, and s ends the post. The key here is the 10 second connection timeout. Once again, lik e I said earlier, the internet connection happens immediately after sending the texts. So, if I go into debug mode and manually step through the process, everyt hing works fine. But if I just run the app on my phone, I will get a connection time out error. Now, I am hoping that if I can reduce the number of text messages to one single text, regardless of the number of recipients, that would be awesome. I have trie d separating the phone numbers with a comma, and that didn't work. I also tried separating the numbers with a semi-colon (exactly like how Microsoft Outlook, or GMail lets you add multiple recipients to an email). None of those worked for m e. Does anyone have any suggestions? Even if there is a different approach altog ether, that would be appreciated. Oh, and I don't want to use the Google Messagi ng intent to send the messages, I need to use my own app.

Vous aimerez peut-être aussi