Akash Kewar
Jul 31, 2021

--

you can just send http request and save the content of the response as a file. Then you can just load the file from the saved location. Here is a code snippet

```

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_about);

MarkdownView markdownView = (MarkdownView) findViewById(R.id.markdown_view);

Functions.Show_loader(this,false,true);

String output_loc = getFilesDir().getAbsolutePath() + File.separator + "About.md";

File markdownFile=new File(output_loc);

// Instantiate the RequestQueue.

RequestQueue queue = Volley.newRequestQueue(this);

String url = file_url;

// Request a string response from the provided URL.

StringRequest stringRequest = new StringRequest(Request.Method.GET, url,

(Response.Listener<String>) response -> {

content = response;

writeToFile(content, About.this, output_loc);

if(markdownFile.exists()){

markdownView.loadMarkdownFromFile(markdownFile);

Functions.cancel_loader();

}

//Loads the markdown file

}, new Response.ErrorListener() {

@Override

public void onErrorResponse(VolleyError error) {

content = "# <center>Unable to fetch the file.</center>";

writeToFile(content, About.this, output_loc);

markdownView.loadMarkdownFromFile(markdownFile);

Functions.cancel_loader();

}

});

// Add the request to the RequestQueue.

queue.add(stringRequest);

```

--

--

Akash Kewar
Akash Kewar

No responses yet