LoadingVersionNumberTask.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Tobias Kaminsky
  5. * Copyright (C) 2017 Tobias Kaminsky
  6. * Copyright (C) 2017 Nextcloud GmbH.
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. package com.owncloud.android.ui.asynctasks;
  22. import android.os.AsyncTask;
  23. import com.owncloud.android.lib.common.utils.Log_OC;
  24. import java.io.BufferedReader;
  25. import java.io.IOException;
  26. import java.io.InputStreamReader;
  27. import java.net.MalformedURLException;
  28. import java.net.URL;
  29. /**
  30. * Class for loading the version number
  31. */
  32. public class LoadingVersionNumberTask extends AsyncTask<String, Void, Integer> {
  33. private static final String TAG = LoadingVersionNumberTask.class.getSimpleName();
  34. protected Integer doInBackground(String... args) {
  35. try {
  36. URL url = new URL(args[0]);
  37. try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))){
  38. return Integer.parseInt(in.readLine());
  39. } catch (IOException e) {
  40. Log_OC.e(TAG, "Error loading version number", e);
  41. }
  42. } catch (MalformedURLException e) {
  43. Log_OC.e(TAG, "Malformed URL ", e);
  44. }
  45. return -1;
  46. }
  47. }