1

Am still new to Android in some stuff and I want to do something that I do on my php script which is kind of a SAAS. There I have some line of code that runs online to check for new update of my cms when the use opens the admin dashboard. I want to do the same with my android app by maybe saving a txt file on a github repository like

http://github.com/wasiro/myapp/version.txt

which I will be updating when i make a major app update

Where i save something like 1.0.9.734 so that my app can get the variable and use it to inform my user that there is a new update alternatively

currenty i have this on my code

public static final String BaseUrl = "http://github.com/wasiro/myapp/version.txt";

Any assistance on achieving this would help alot and if there are better ways to do it please enlighten me.

Don't confuse this to JSON because I want to use GitHub to store my variable like I do with my phone script

Edit: When I tried this instead of the variable in the file being extracted and read it was the path to the file that got on the way of the code

  • Possible duplicate of [What is the most efficient way on Android to call HTTP Web API calls that return a JSON response?](https://stackoverflow.com/questions/19050294/what-is-the-most-efficient-way-on-android-to-call-http-web-api-calls-that-return). Even if this question is about JSON and not text data the general approach is more or less the same. May be JSON is even better for what you want. – Robert Mar 25 '19 at 19:14
  • @Robert I want to use GitHub to store my variable and not some custom server somewhere. –  Mar 25 '19 at 20:16
  • It seems like it would work. I'm not exactly sure what you're asking for though. You should be able to download and parse a file without much issue. – Nick Vitha Mar 25 '19 at 20:20
  • I have tried but it does not work on java like it works on php –  Mar 25 '19 at 20:25

1 Answers1

0

I think everyone is too quick to brush the question aside to being a duplicate instead of understanding what is all about? So sad this is what the SO community has become.

Your issue is to open a file located elsewhere.

private class myStreamReader extends AsyncTask<String, Void, String> {
    String str = "";
    @Override
    protected String doInBackground(String... params) {
        try {
            URL url = new URL("http://github.com/wasiro/myapp/version.txt");
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            str = in.readLine();
            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }

        return "Executed";
    }

    @Override
    protected void onPostExecute(String result) {
        //do something here
         httpStuff.setText(str);
    }

    @Override
    protected void onPreExecute() {}

    @Override
    protected void onProgressUpdate(Void... values) {}
}
Jack Siro
  • 677
  • 10
  • 29
  • Thanks so much for this answer. At least you so all the people understood what I wanted –  Mar 26 '19 at 04:35