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

  • SEARCH
  • Home
  • 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 6319067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:44:21+00:00 2026-05-24T15:44:21+00:00

In Android I want to call webservice which is made into php with Json

  • 0

In Android I want to call webservice which is made into php with Json response.
How to call that webservice and how to store the response into array?

  • 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-24T15:44:22+00:00Added an answer on May 24, 2026 at 3:44 pm

    I would recommend looking into REST services. The basic structure is to have your android app preform HTTP requests(preferably in a separate thread) to the server and have the server respond with xml or json.

    Heres a threaded http post class i use often.

    import java.util.ArrayList;
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.message.BasicNameValuePair;
    import org.apache.http.params.BasicHttpParams;
    import org.apache.http.params.HttpConnectionParams;
    import org.apache.http.params.HttpParams;
    import org.apache.http.util.EntityUtils;
    import android.os.Handler;
    import android.os.Message;
    
    public class HttpPostThread extends Thread {
        public static final int FAILURE = 0;
        public static final int SUCCESS = 1;
        public static final String VKEY = "FINDURB#V0";
    
        private final Handler handler;
        private String url;
        ArrayList<NameValuePair> pairs;
    public HttpPostThread(String Url, ArrayList<NameValuePair> pairs, final Handler handler)
    {
    this.url =Url;
        this.handler = handler;
        this.pairs = pairs;
        if(pairs==null){
            this.pairs = new ArrayList<NameValuePair>();
        }
    }
    
    
    @Override
    public void run()
    {
    try {
    
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(url);
    HttpParams httpParameters = new BasicHttpParams();
    int timeoutConnection = 3000;
     HttpConnectionParams.setConnectionTimeout(httpParameters, 
             timeoutConnection); 
    if(pairs!=null)
        post.setEntity(new UrlEncodedFormEntity(pairs));
        HttpResponse response = client.execute(post);
        HttpEntity entity = response.getEntity();  
        String answer = EntityUtils.toString(entity);
        Message message = new Message();
                message.obj = answer;
                message.what = HttpPostThread.SUCCESS;
                handler.sendMessage(message);
    
    
    } catch (Exception e) {
        e.printStackTrace();
        handler.sendEmptyMessage(HttpPostThread.FAILURE);
    }
    
    }
    }
    

    Whenever you need to communicate with the server you do something like this.

    Handler handler = new Handler()
        {
            @Override
            public void handleMessage(Message msg)
            {
                removeDialog(0);
                switch (msg.what)
                {
                case HttpPostThread.SUCCESS:
                    String answer = (String)msg.obj;
                    if (answer != null)
                    {
                    try {
                         JSONObject jsonObj = new JSONObject(answer);
                         String message = jsonObj.getString("msg");
                    } catch (JSONException e) {
                          e.printStackTrace();
                    }
                    }
                    break;
    
                    case HttpPostThread.FAILURE:
                    // do some error handeling
                    break;
    
                    default:
                    break;
                 }
            }
     }
     ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
     pairs.add(new BasicNameValuePair("key", "value"));
     HttpPostThread thread = new  HttpPostThread("http://serviceURL",pairs, handler);
     thread.start();
    

    To answer you question below, the service can be implemented with any number of technologies. Below is a simple example of a php service that gets the key/value pair from the example above.

    Example of a simple PHP service

        <?php
        $value = $_POST['key'];
        $msg "The value".$value. "was received by the service!";
        echo json_encode($msg);
        ?>
    

    When the server responds handleMessage will be called and the value inside of answer be whatever your php service echos.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass an array from my Android application to my SOAP webservice
I can call a webservice with KSOAP2 from android,now i want to know is
I am a newbie to Android platform. I want to call a webservice from
I am new android developer and i want create a webservice in php and
i am working in android. i want to call a number which is displaying
I want to answer a phone call. I found the intent android.intent.action.ANSWER but it
I want to write an application for Android devices that interacts with the surface
I want to make an android application that shows a listing of applications (downloaded
I want to create an application for Android that will be able to scan
I want to implement an android app which compares recorded audio files with our

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.