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();
- }
- }
- }
- }
- new ProgressTask().execute((PublicVar.URL + "server_connect=" + "VersionApp: "
- + BuildConfig.VERSION_NAME + ";_SDK:_"+ Integer.toString(Build.VERSION.SDK_INT) + ";_ModelPhone:_" + android.os.Build.MODEL.toString()).replaceAll(" ", "_"));
- static final String URL = "https://www.site.000webhost.com/api.php?"; //(работает)
- static final String URL = "http://www.site.online/api.php?"; //(не работает)
Add Comment
Please, Sign In to add comment