Android Open Source - android Token Async






From Project

Back to project page android.

License

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.

Java Source Code

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;
  }
}




Java Source Code List

helper.ClientInterface.java
helper.ClientToServer.java
helper.CommonUtilities.java
helper.ConnectionDetector.java
helper.KorbanAsync.java
helper.RegisterAsync.java
helper.RelawanAsync.java
helper.TokenAsync.java
helper.peopleData.java
php.id.ganapatih.GcmBroadcastReceiver.java
php.id.ganapatih.GcmIntentService.java
php.id.ganapatih.Home.java
php.id.ganapatih.Maps.java
php.id.ganapatih.SplashScreen.java
php.id.ganapatih.Welcome.java