Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ProgressTask extends AsyncTask<String, Void, String> {
- @Override
- protected String doInBackground(String... path) {
- String content;
- try {
- content = getContent(path[0]);
- } catch (IOException ex) {
- content = ex.getMessage();
- }
- return content;
- }
- @Override
- protected void onPostExecute(String content) { //метод для получения ответа
- if (content.equals("server_connect")){
- Intent intent = new Intent(MainActivity.this, MainCl.class);
- startActivity(intent);
- } else {
- Toast.makeText(getApplicationContext(),R.string.server_error, Toast.LENGTH_LONG).show();
- }
- pb.setVisibility(View.INVISIBLE);
- btn.setText(R.string.next);
- btn.setEnabled(true);
- }
- private String getContent(String path) throws IOException {
- BufferedReader reader = null;
- try {
- URL url = new URL(path);
- HttpsURLConnection c = (HttpsURLConnection) url.openConnection();
- c.setRequestMethod("GET");
- c.setReadTimeout(PublicVar.time);
- c.connect();
- reader = new BufferedReader(new InputStreamReader(c.getInputStream()));
- StringBuilder buf = new StringBuilder();
- String line = null;
- while ((line = reader.readLine()) != null) {
- buf.append(line);
- }
- return (buf.toString());
- } finally {
- if (reader != null) {
- reader.close();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment