final EditText login = (EditText)findViewById(R.id.login); final EditText password = (EditText)findViewById(R.id.password); final EditText password2 = (EditText)findViewById(R.id.password2); //
// 3 doInBackground, onPostExecute class AsyncTaskExample extends AsyncTask<Void, Integer, String> { // @Override protected String doInBackground(Void... params) { } // doInBackground, UI protected void onPostExecute(String result) { } catch (JSONException e) { e.printStackTrace(); } } } // new AsyncTaskExample().execute();
public class ServerSendData { private static String server = "http://xxx.xxx.x.xxx/"; public static String mlogin = null; public static String mpassword = null; public static String sendRegData(String login,String password) { String result = null; mlogin = login; mpassword = password; try { URL url = new URL("" + server + "apiregistration/create/"+mlogin+"/"+mpassword+""); URLConnection connection = url.openConnection(); HttpURLConnection httpConnection = (HttpURLConnection)connection; int responseCode = httpConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { InputStream in = httpConnection.getInputStream(); BufferedReader r = new BufferedReader(new InputStreamReader(in)); result = r.readLine(); Log.w("res",""+result+""); } else { } } catch (MalformedURLException e) {} catch (IOException e1) {} return result; }
{"status":"login_busy"}
return ServerSendData.sendRegData(""+login.getText().toString()+"",""+ password.getText().toString()+"");
JSONObject object = new JSONObject(result); String status = object.getString("status"); // status login_busy
Source: https://habr.com/ru/post/165251/
All Articles