How to get value form server database with android
AndroidManifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
class YourClassName extends AsyncTask<String, String, String> {
@Override protected void onPreExecute() {
super.onPreExecute();
//put necessary code here
}
/** * loading data */ protected String doInBackground(String... args) {
// Building Parameters List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Your Key", Your value));
// getting JSON Object
JSONObject json = jsonParser.makeHttpRequest(url, "POST", params);
// for checking Log.d("Create Response", json.toString());
// check for success tag try {
int success = json.getInt(SUCCESS);
if (success == 1) {
//get data to json array your json array= json.getJSONArray(your key);
//get length
for (int i = 0; i<jsonarray.length(); i++) {
//get jasonobject and store in arraylist JSONObject jsnobj = your_jason_array.getJSONObject(i);
String variable = jsnobj.getString(key);
}
} else {
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/** * After completing background task Dismiss the progress dialog * * */ protected void onPostExecute(String file_url) {
}
}