1

Please don´t be too harsh to me concerning any mistakes with this question since thats my first one here.

So basically what i want to do is reading/showing a PDF document in my Android App after pressing a button. The PDF is located on a Raspberry Pi 3 and i found a code example on this thread how to read it. Before accessing it however, i call a python script on the Raspi which is (re)creating the PDF based on a database.

So the user presses the button in the App and sees a PDF which presents the current state of a database table.

Now i got the following code in my Activity to call the script and read the PDF:

                                new AsyncTask<Integer, Void, Void>(){
                                @Override
                                protected Void doInBackground(Integer... params) {
                                    try {
                                        executeRemoteCommand("user","pw","ip", port, "command to execute the python script");
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    return null;
                                }
                            }.execute(1);
                            //waiting for the PDF to be created
                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    String url = "http://IP/path/file.pdf";
                                    Intent i = new Intent(Intent.ACTION_VIEW);
                                    i.setData(Uri.parse(url));
                                    startActivity(i);
                                }
                            }, 5000);

With this code connecting to the Raspberry, executing the python script, thus updating the database and reading the PDF file works just fine.

But i have the following problem:

When i close the PDF view in my App, add something to the database and press the executing button again the PDF file itself is being updated (i checked that on the Raspberry) but then the App still shows the old version of it. Even when i restart the App and execute this again it still shows the first version of the PDF...

Does anyone have an idea why and how to fix this?

Is there any kind of cache which stores the PDF and just shows the same every time i read from the Raspberry?

Community
  • 1
  • 1
DKon
  • 11
  • 2
  • 1
    Add `?ts=x` to url where x = timestamp... The file.pdf is static resources so both serverside and http client trying to cache it(of course it depends on settings)... Adding random parameter should avoid this(in most cases, still it depends on webserver settings) – Selvin Nov 07 '16 at 14:08
  • "but then the App still shows the old version of it" -- no, it does not. The PDF viewer app or Web browser shows the old version of it. You did not write the PDF viewer app or Web browser. You are merely launching it via `startActivity()`. "Does anyone have an idea why" -- perhaps your Web server is including inappropriate headers, indicating that the PDF has not changed, when in reality it has. Beyond that, if you want to control the download process, download the PDF yourself. – CommonsWare Nov 07 '16 at 14:21
  • @CommonsWare Yea i meant the launched Activity, badly expressed myself sorry. – DKon Nov 07 '16 at 14:37
  • I implemented a random part in the URL as suggested by @Selvin and now it works as intended. The freshly updated PDF is now displayed in the Activity. Thanks :) – DKon Nov 07 '16 at 14:38

0 Answers0