I'm new in android and had tried to find any refer/tutorial on internet but not yet fixing my issues
I have this code to show the value :
List<Contact> contacts = db.test();
for (Contact cn : contacts) {
String log = "Audit Name "+cn.getName()+" ,CountAudit " + cn.getAudit()+" ,CountFlag "
+ cn.getFlag();
if(String.valueOf(cn.getFlag()).equals(cn.getAudit())){
Log.d("Berhasil", "Sama Cok");
}
Log.d("Name: ", log);
}
the logcat shows :
Audit Name 12447 ,CountAudit 1 ,CountFlag 1
now I need to create HttpURLConnection
that can stored Audit Name
value to API
I'm creating new class :
private class sendget extends AsyncTask<Void, String, Void >
{
@Override
protected Void doInBackground(String audit) {
try {
URL url = new URL("myurl"+"?"+ audit);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
conn.setRequestProperty("Accept", "application/json");
conn.setDoOutput(true);
conn.setDoInput(true);
DataOutputStream os = new DataOutputStream(conn.getOutputStream());
//os.writeBytes(URLEncoder.encode(jsonParam.toString(), "UTF-8"));
os.writeBytes(audit);
os.flush();
os.close();
conn.disconnect();
} catch (JSONException | IOException e) {
e.printStackTrace();
}
}
}
but I've too much error,
My Goal is to using this code :
List<Contact> contacts = db.test();
for (Contact cn : contacts) {
String log = "Audit Name "+cn.getName()+" ,CountAudit " + cn.getAudit()+" ,CountFlag "
+ cn.getFlag();
if(String.valueOf(cn.getFlag()).equals(cn.getAudit())){
// add this code to calling httpurlconnection class with parameter from cn.getName()
sendget.execute(cn.getName);
// so the complete url gonna be myurl?audit=12447
Log.d("Berhasil", "Sama Cok");
}
Log.d("Name: ", log);
}
Kindly someone guide me to create HttpURLConnection
class that work to above code, any tutorial would be glad