SHARE
TWEET

Untitled

Tester1Alex May 23rd, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.wikitude.samples.AsyncTasks_For_Work;
  2.  
  3. import android.content.Context;
  4. import android.os.AsyncTask;
  5. import android.util.Log;
  6.  
  7. import java.io.BufferedReader;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.io.InputStreamReader;
  11. import java.net.HttpURLConnection;
  12. import java.net.MalformedURLException;
  13. import java.net.URL;
  14. import java.nio.charset.StandardCharsets;
  15. import java.util.Objects;
  16.  
  17. public class Downloader_Photo extends AsyncTask<Void,String,String> {
  18.      private Context context;
  19.  
  20.     public Downloader_Photo(Context context){
  21.         this.context=context;
  22.     }
  23.     @Override
  24.     protected void onPostExecute(String s) {
  25.      //   Log.d("s_final: ",s);
  26.        // AlertDialog.Builder builder=new AlertDialog.Builder(context);
  27.        // builder.setMessage(s)
  28.        //         .create()
  29.         //        .show();
  30.         super.onPostExecute(s);
  31.     }
  32.  
  33.     @Override
  34.     protected String doInBackground(Void... strings) {
  35.         StringBuilder result=null;
  36.         try {
  37.  
  38.  
  39.             String login_url = "http://alexar.zzz.com.ua/DownloadFromBase.php";
  40.             URL url = new URL(login_url);
  41.             HttpURLConnection httpURLConnection  = (HttpURLConnection) url.openConnection();
  42.             //Objects.requireNonNull(httpURLConnection).setRequestMethod("GET");
  43.  
  44.             httpURLConnection.setDoOutput(true);// приложение намеревается записать данные в URL-соединение.
  45.             httpURLConnection.setDoInput(true);//приложение намерено считывать данные из URL-соединения.
  46.             InputStream inputStream = httpURLConnection.getInputStream();
  47.             BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.ISO_8859_1));
  48.              result = new StringBuilder();
  49.             String line;
  50.             while ((line = bufferedReader.readLine()) != null) {
  51.                 result.append(line);
  52.  
  53.             }
  54.             Log.d("s_final 1: ",result.toString());
  55.             // alertDialog.setMessage(result.toString());
  56.             bufferedReader.close();
  57.             inputStream.close();
  58.             httpURLConnection.disconnect();
  59.         }
  60.         catch (MalformedURLException e)
  61.         {
  62.         e.printStackTrace();
  63.         }
  64.         catch (IOException e)
  65.         {
  66.         e.printStackTrace();
  67.         }
  68.         return Objects.requireNonNull(result).toString();
  69.     }
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top