i use by code Under for get date by formate jsone in eclips but this not working in android stadio 1.5 by sdk 23 Please help me under clase i use for conect server in eclips and working i need sample like this for Android stadio by sdk 23 and higher
package com.example.servicshareandread;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
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 android.widget.Toast;
public class Webservice {
public static String readUrl(String url, ArrayList<NameValuePair> params) {
try {
HttpClient client = new DefaultHttpClient();
HttpPost method = new HttpPost(url);
if (params != null) {
method.setEntity(new UrlEncodedFormEntity(params));
}
HttpResponse response = client.execute(method);
InputStream inputStream = response.getEntity().getContent();
String result = convertInputStreamToString(inputStream);
return result;
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static String convertInputStreamToString(InputStream inputStream) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder builder = new StringBuilder();
String line = "";
while ((line = reader.readLine()) != null) {
builder.append(line);
}
return builder.toString();
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
i use class Webservice by under coode
public void loadsharepoint()
{
gotomap=(ImageView)findViewById(R.id.imggomaptab2);
listshare=(ListView)findViewById(R.id.listlocationsharetab2);
String StrWeb = Webservice.readUrl("http://gorab.ir/map/search.php", null);
String Temp = "";
try {
JSONArray list = new JSONArray(StrWeb);
maylocationget=new ArrayList<StructTest>();
maylocationget.clear();
for (int i = 0; i < list.length(); i++)
{
StructTest record=new StructTest();
JSONObject obj1 = list.getJSONObject(i);
record.id = obj1.getInt("id");
record.gid = obj1.getInt("gid");
record. lat= obj1.getDouble("lat");
record.longg = obj1.getDouble("long");
record.title =CodeAndDecode.deCoder64(obj1.getString("title"));
record.discription =CodeAndDecode.deCoder64( obj1.getString("discription"));
record.addres = CodeAndDecode.deCoder64(obj1.getString("addrestiping"));
maylocationget.add(record);
}
G.pepelerecord.clear();
for (int i = 0; i < maylocationget.size(); i++) {
G.pepelerecord.add(maylocationget.get(i));
}
adapterget = new AdapterTest2(G.pepelerecord);
listshare.setAdapter(adapterget);
}
catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i need help...
Add your gradle dependencies compile 'com.loopj.android:android-async-http:1.4.9'
and add code below in your activity. You can find here more about Android Asynchronous Http Client library.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AsyncHttpClient client = new AsyncHttpClient();
client.get("your_url", null, new JsonHttpResponseHandler(){
private ProgressDialog progressCircle;
@Override
public void onStart() {
super.onStart();
progressCircle = new ProgressDialog(MainActivity.this);
progressCircle.setCancelable(true);
progressCircle.setMessage("Wait ...");
progressCircle.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressCircle.show();
}
@Override
public void onFinish() {
super.onFinish();
progressCircle.cancel();
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
int lengthJSONArray = response.length();
for (int i = 0; i < lengthJSONArray; i++) {
try {
StructTest record=new StructTest();
JSONObject obj1 = response.getJSONObject(i);
record.id = obj1.getInt("id");
record.gid = obj1.getInt("gid");
record. lat= obj1.getDouble("lat");
record.longg = obj1.getDouble("long");
record.title =CodeAndDecode.deCoder64(obj1.getString("title"));
record.discription =CodeAndDecode.deCoder64( obj1.getString("discription"));
record.addres = CodeAndDecode.deCoder64(obj1.getString("addrestiping"));
maylocationget.add(record);
} catch (JSONException e) {
e.printStackTrace();
}
}
adapter.notifyDataSetChanged();
}
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.