Back to project page android.
The source code is released under:
Copyright (c) 2014, ganapatih All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Re...
If you think the Android project android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package helper; //from w w w . j a v a 2 s . co m import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.content.Context; public class TokenAsync { private Context mainContext; private Activity CallerActivity; public TokenAsync(Context c, Activity a) { mainContext = c; CallerActivity = a; } public String getToken(){ String url = CommonUtilities.SERVER_URL_TOKEN; String sReturn = ""; HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); try { HttpResponse response = client.execute(request); InputStream in = response.getEntity().getContent(); BufferedReader reader = new BufferedReader( new InputStreamReader(in)); StringBuilder str = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { str.append(line + "\n"); } in.close(); sReturn = str.toString(); } catch (Exception e) { // writing exception to log e.printStackTrace(); } String token = ""; if(sReturn != ""){ try { JSONObject jsonObj = new JSONObject(sReturn); token = jsonObj.getString("_token"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return token; } }