update get api
This commit is contained in:
parent
63e6a5b7dd
commit
a494c02d90
|
@ -61,6 +61,49 @@ public class HttpCallHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String executeGetBalance(String urlParam){
|
||||||
|
BufferedReader bufferedReader = null;
|
||||||
|
HttpURLConnection connection = null;
|
||||||
|
String res = null;
|
||||||
|
try{
|
||||||
|
URL url = new URL(urlParam);
|
||||||
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.connect();
|
||||||
|
|
||||||
|
int statusCode = connection.getResponseCode();
|
||||||
|
|
||||||
|
if(statusCode != 200){
|
||||||
|
return null;
|
||||||
|
}else {
|
||||||
|
bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while ((line = bufferedReader.readLine())!=null){
|
||||||
|
stringBuilder.append(line);
|
||||||
|
}
|
||||||
|
JSONObject jsonSuccess = new JSONObject(stringBuilder.toString());
|
||||||
|
jsonSuccess.put("status",200);
|
||||||
|
res = jsonSuccess.toString();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
if(connection!=null){
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
if(bufferedReader != null){
|
||||||
|
try{
|
||||||
|
bufferedReader.close();
|
||||||
|
}catch (IOException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String executeLoginHttp(String urlParam, String[] params){
|
public String executeLoginHttp(String urlParam, String[] params){
|
||||||
BufferedReader bufferedReader = null;
|
BufferedReader bufferedReader = null;
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
|
|
|
@ -11,6 +11,8 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import com.example.monnthic.monnethicmobile.R;
|
import com.example.monnthic.monnethicmobile.R;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
@ -19,13 +21,14 @@ import java.net.URL;
|
||||||
|
|
||||||
import monnethic.mobile.database.User;
|
import monnethic.mobile.database.User;
|
||||||
import monnethic.mobile.restApi.Config;
|
import monnethic.mobile.restApi.Config;
|
||||||
|
import monnethic.mobile.restApi.HttpCallHandler;
|
||||||
import monnethic.mobile.transaction.MakePayementActivity;
|
import monnethic.mobile.transaction.MakePayementActivity;
|
||||||
import monnethic.mobile.transaction.ReceivePayementActivity;
|
import monnethic.mobile.transaction.ReceivePayementActivity;
|
||||||
|
|
||||||
public class UserAccountActivity extends AppCompatActivity {
|
public class UserAccountActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private TextView balance;
|
private TextView balance;
|
||||||
private String strUrl = Config.QUERY_BALANCE+"b";
|
private String strUrl = Config.QUERY_BALANCE;
|
||||||
private String result;
|
private String result;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -68,7 +71,8 @@ public class UserAccountActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
new GetUserBalanceTask().execute(strUrl);
|
String[] params = {strUrl,"b"};
|
||||||
|
new GetUserBalanceTask().execute(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPayement(){
|
public void sendPayement(){
|
||||||
|
@ -107,46 +111,16 @@ public class UserAccountActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(String... params) {
|
protected String doInBackground(String... params) {
|
||||||
System.out.println(params[0]);
|
|
||||||
InputStream inputStream = null;
|
|
||||||
HttpURLConnection conn = null;
|
|
||||||
try{
|
try{
|
||||||
URL url = new URL(params[0]);
|
String url = Config.QUERY_BALANCE+params[0];
|
||||||
conn = (HttpURLConnection) url.openConnection();
|
HttpCallHandler httpCallHandler = new HttpCallHandler();
|
||||||
conn.setRequestMethod("GET");
|
JSONObject json = new JSONObject(httpCallHandler.executeGetBalance(url));
|
||||||
conn.connect();
|
Double balance = json.getDouble("userBalance");
|
||||||
|
return balance.toString();
|
||||||
int response = conn.getResponseCode();
|
|
||||||
if(response != 200){
|
|
||||||
return "Error response";
|
|
||||||
}
|
|
||||||
|
|
||||||
inputStream = conn.getInputStream();
|
|
||||||
if(inputStream == null){
|
|
||||||
return "Error inputStream";
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
String line;
|
|
||||||
|
|
||||||
while ((line = reader.readLine())!=null){
|
|
||||||
buffer.append(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
String value = new String(buffer);
|
|
||||||
|
|
||||||
System.out.println("result is "+value);
|
|
||||||
result = value;
|
|
||||||
|
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
System.out.println("Exception : "+e);
|
e.printStackTrace();
|
||||||
} finally {
|
return null;
|
||||||
if(conn != null){
|
|
||||||
conn.disconnect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue