1

My Android app needs to get a configuration string from a server on each start. I thought of creating a blank HTML page containing just this string. The app would then execute an http_get request to get that string from the server.

Is there a more elegant and free solution? (I don't have a webserver and most free websites embed ads or headers/footers into the html).

I tried this solution:

URL txtUrl = new URL("https://sites.google.com/site/myName/myText.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(txtUrl.openStream()));
String inputLine = in.readLine();

This works, but there is a 1-2 second delay.

Mika
  • 5,807
  • 6
  • 38
  • 83
A.G.
  • 2,037
  • 4
  • 29
  • 40
  • Is this an android app? – Mika May 29 '15 at 11:22
  • Are u talking about System property? – Bacteria May 29 '15 at 11:44
  • I edited my answer to reflect your edited question. If you give a concrete example of what you are sending and expecting to retrieve I can tweak the code further. – Mika May 29 '15 at 13:06
  • I'm not sending anything to the server. The response from the server is a String containing configuration parameters that the app should use. The string is at most 100 chars long. Like this, I will be able to control the app behavior without having to upload a new apk to PlayStore. – A.G. May 29 '15 at 14:07

3 Answers3

1

Put the String as a parameter in the URL.

http://example.com/page?parameter=value

Check this question

Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
1

There are many services that will allow you to host information in the cloud and return it to your app. These are called backend as a service (BAAS). You will find that most have a free lower tier you can use. Examples are parse.com and firebase.com

Using google sites is very inefficient for what you are trying to do. Take a look at parse you can write something like this:

ParseQuery<ParseObject> query = ParseQuery.getQuery("YOUR_OBJECT");    
query.getInBackground("YOUR_STRING", new GetCallback<ParseObject>() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // object will have your return string
    } else {
      // something went wrong
    }
  }
});
Mika
  • 5,807
  • 6
  • 38
  • 83
0

You can go ahead and create and define your configuration object which you can send back as JSON or XML response back to the client. The advantage of doing this is that you have a great number of libraries that would do the hard work of converting to and from the configuration object.

Of course, you would want to make the configuration object extensible (name by using Key value pairs) so that you can add additional properties to the configuration easily at a later stage.

Prahalad Deshpande
  • 4,709
  • 1
  • 20
  • 22