Java tutorial
package jp.co.rakuten.rakutenvideoplayer.api; import java.io.Reader; import java.util.List; import jp.co.rakuten.rakutenvideoplayer.connection.ServerConnection; import jp.co.rakuten.rakutenvideoplayer.interfaceproject.UpdateData; import jp.co.rakuten.rakutenvideoplayer.model.Model_OauthAuthentication; import jp.co.rakuten.rakutenvideoplayer.model.Model_LicenseCode; import jp.co.rakuten.rakutenvideoplayer.model.Model_RequestOauth; import jp.co.rakuten.rakutenvideoplayer.model.play.PlayModel; import jp.co.rakuten.rakutenvideoplayer.util.APIExceptionUtil; import jp.co.rakuten.rakutenvideoplayer.util.Constant; import jp.co.rakuten.rakutenvideoplayer.util.Constant.API; import jp.co.rakuten.rakutenvideoplayer.util.DLog; import org.apache.http.NameValuePair; import android.os.AsyncTask; /** * * @author nguyenvantu * */ public class Api_reRequestOauth extends AsyncTask<List<NameValuePair>, String, Model_RequestOauth> { private String API_NAME = "/oauth/token.json"; private UpdateData context; private API ERROR = API.NO_ERROR; private int type = Constant.GET; public Api_reRequestOauth(UpdateData context) { this.context = context; } @Override protected Model_RequestOauth doInBackground(List<NameValuePair>... params) { // TODO Auto-generated method stub ServerConnection connect = new ServerConnection(Constant.URL, API_NAME, params[0], type); Reader json_con; Model_RequestOauth model = null; try { json_con = connect.connect(); Parser parser = new Parser(API.REREQUESTOAUTH); if (json_con != null) { model = (Model_RequestOauth) parser.getModel(json_con); } } catch (Exception e) { e.printStackTrace(); ERROR = APIExceptionUtil.detectAPIError(e); } return model; } @Override protected void onPostExecute(Model_RequestOauth result) { // TODO Auto-generated method stub if (context != null) { if (ERROR.equals(API.NO_ERROR)) { context.receiveData(result, Constant.API.REREQUESTOAUTH); if (result == null) { DLog.e("KOP", "null"); } } else { context.receiveData(result, ERROR); } } super.onPostExecute(result); } }