LoadingVersionNumberTask.java 1.7 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.URL;
  28. /**
  29. * Class for loading the version number
  30. */
  31. public class LoadingVersionNumberTask extends AsyncTask<String, Void, Integer> {
  32. private static final String TAG = LoadingVersionNumberTask.class.getSimpleName();
  33. protected Integer doInBackground(String... args) {
  34. try {
  35. URL url = new URL(args[0]);
  36. BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
  37. Integer latestVersion = Integer.parseInt(in.readLine());
  38. in.close();
  39. return latestVersion;
  40. } catch (IOException e) {
  41. Log_OC.e(TAG, "Error loading version number", e);
  42. }
  43. return -1;
  44. }
  45. }