unitedartinc unitedartinc - 6 months ago 23
Android Question

Fetch Data from text file in a server to an Android app

We have an app that we are using it to fetch some Images from a server, and we are doing it through direct URL fetching. Also there are some other data along with each URL like its Title, Thumbnail URL, OriginalLinks etc.

Below is how we are fetching the data currently

public class Images {

public final static String[] Image_webLinks = new String[] {

public final static String[] Image_Titles = new String[] {
"My Image 1",
"My Image 2",
"My Image 3",

public final static String[] ImageView_Urls = new String[] {

public final static String[] ThumbnailUrls = new String[] {

We know that this may not be the right way to fetch data from the server, But we have a simple requirement.Is there a way to store the String data in some text file and fetch it directly from online and thus updating the string data every time, Doing this we don't need to update the code if we want to add an Extra URL in future. We only need to update the Text file inside the server.Is it possible? how?


You can use this code

 new AsyncTask<String, Void, String>()

            protected String doInBackground(String[] params) {
                    String line;
                    URL url = new URL("http://nomediakings.org/everyoneinsilico.txt");
                    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                    String str="";
                    while ((line = in.readLine()) != null) {
                }catch (Exception ex)
                return null;