Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6223067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:25:27+00:00 2026-05-24T08:25:27+00:00

I have this code: protected void onHandleIntent(Intent intent) { while (true){ long endTime =

  • 0

I have this code:

protected void onHandleIntent(Intent intent) {
      while (true){

          long endTime = System.currentTimeMillis() + 5*1000;
          while (System.currentTimeMillis() < endTime) {
              synchronized (this) {
                  try {
                      wait(endTime - System.currentTimeMillis());


                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost("http://www.***.***/***/request_sms.php");
                    String HTML = "";
                    try {
                        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                        nameValuePairs.add(new BasicNameValuePair("id", "1"));
                        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                        HttpResponse response = httpclient.execute(httppost);
                        HTML = EntityUtils.toString(response.getEntity());
                    } catch (ClientProtocolException e) {} catch (IOException e) {} 


                        if(HTML.indexOf("[NO TEXTS]") > 0) {

                        } else {
                            Vector<String> all_sms = getBetweenAll(HTML, "<sms>", "<sms>");
                            for(int i = 0, size = all_sms.size(); i < size; i++) {
                                String from = getBetween(all_sms.get(i), "<from>", "</from>");
                                String to = getBetween(all_sms.get(i), "<to>", "</to>");
                                String msg = getBetween(all_sms.get(i), "<msg>", "</msg>");
                                String sent = getBetween(all_sms.get(i), "<sent>", "</sent>");
                                String HTML1 = "";
                                HttpClient httpclient1 = new DefaultHttpClient();
                                HttpPost httppost1 = new HttpPost("http://www.***.***/***/add_sms.php");
                                try {
                                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                                    nameValuePairs.add(new BasicNameValuePair("from", from));
                                    nameValuePairs.add(new BasicNameValuePair("to", to));
                                    nameValuePairs.add(new BasicNameValuePair("msg", msg));
                                    nameValuePairs.add(new BasicNameValuePair("sent", sent));
                                    httppost1.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                                    HttpResponse response1 = httpclient1.execute(httppost1);
                                    HTML1 = EntityUtils.toString(response1.getEntity());
                                    HN.post(new DisplayToast(HTML1)); 
                                } catch (ClientProtocolException e) {} catch (IOException e) {} 

                            }
                        }


                      } catch (Exception e) {
                  }
              }
          }

        }


  }

This is a service, what I want it to do is every 5 seconds request a page that has the pending SMS messages that the phone needs to send. I am not at the sending part, I just want the HN.Post(DisplayToast(HTML1)) to show up and then I will work. What HTML1 should contain is “success”, but I don’t get anything. I am sure that HTML does not contain “[NO TEXTS]” as I have tested and it shows the tag with the other tags inside of it. What could be wrong? Here are the functions used:

Handler HN = new Handler(); 


  private class DisplayToast implements Runnable {

    String TM = "";

        public DisplayToast(String toast){
            TM = toast; 
        }

        public void run(){
           Toast.makeText(getApplicationContext(), TM, Toast.LENGTH_SHORT).show();
        }
  }

  public String getBetween(String source, String start, String end) {

        int startindex = source.indexOf(start);
        int endindex = source.indexOf(end, startindex);

        String result = source.substring(startindex + start.length(), endindex);

        return result;
    }

  public Vector<String> getBetweenAll(String source, String start, String end) {
        int startI = 0;
        Vector<String> result = new Vector<String>();
        while (startI + (start.length() + end.length()) < source.length()) {
            int startindex = source.indexOf(start, startI);
            if (startI > startindex) {
                break;
            }
            int endindex = source.indexOf(end, startindex);
            result.add(source.substring(startindex + start.length(), endindex));
            startI = endindex;
        }
        return result;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:25:28+00:00Added an answer on May 24, 2026 at 8:25 am

    Use org.apache.http.impl.client.BasicResponseHandler for getting the HTML content.

    HTML1 = httpclient1.execute(httppost1, new BasicResponseHandler());
    HN.post(new DisplayToast(HTML1)); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: protected void onListItemClick(ListView l, View v, int position, long id)
I have this code protected void Page_Load(object sender, EventArgs e) { DataSet.DestinationsDataTable GetDestinations =
I have this code inside my asynctask: @Override protected void onPreExecute() { waitDialog =
I thought that if I have this code: public event PropertyChangedEventHandler PropertyChanged; protected void
I have this in my LoginControl.ascx code behind: protected void Logout_Click(object sender, EventArgs e)
I have this code: protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) {
I have this code in my codebehind... protected void Page_Init(object sender, EventArgs e) {
I have this code in base class protected virtual bool HasAnyStuff<TObject>(TObject obj) where TObject:class
I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row
I have this code fragment: public static class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.