I need to use this api,
"http://sconysoft.com/api/md5.php?q="
for doing something like this app :
https://play.google.com/store/apps/details?id=com.sconysoft.md5encoderdecoder&hl=en
Actually, i have one button with Two EditText
in Android app, just i need send first string to this api, and if this hash encoded(in url) exist, show that in Edit Text2
.
and this is above app Codec class :
public class Codec {
public String decode(String md5) throws Exception {
try {
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(new HttpGet("http://sconysoft.com/api/md5.php?q=" + md5));
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
JSONObject jo = new JSONObject(br.readLine());
if(jo.getString("md5").equals(""))
throw new Exception();
return jo.getString("word");
} catch (Exception e) {
}
throw new Exception("Can't decode given md5");
}
}
main :
public boolean isNetworkAvailable() {
ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
return true;
}
return false;
}
public void decode(View view) {
final EditText etWord = (EditText)findViewById(R.id.edit1);
final EditText etMd5 = (EditText)findViewById(R.id.edit2);
if(!isNetworkAvailable()) {
etWord.setText("Network unavailable");
return;
}
final ProgressDialog pd = ProgressDialog.show(view.getContext(),"Waiting for Server", "It should take a few seconds");
Thread th = new Thread() {
@Override
public void run() {
try {
Codec cd = new Codec();
String md5 = etMd5.getText().toString();
try {
final String word = cd.decode(md5);
runOnUiThread(new Runnable() {
public void run() {
etWord.setText(word);
pd.dismiss();
}
});
} catch (final Exception e) {
runOnUiThread(new Runnable() {
public void run() {
etWord.setText(e.getMessage());
pd.dismiss();
}
});
}
} catch(Exception e) {
runOnUiThread(new Runnable() {
public void run() {
pd.dismiss();
}
});
}
}
};
th.start();
}
}
i also try this codes with same situation in developing, but unfortunately, this codes doesn't work and i cannot see this buttons codes or other something on this app codes.
Can someone help me, how to doing this with one button and Two EditTexts?
Need some help about doing this with above API.