0

I have an Android app where I intercept a PDF file download event in the WebView, download it using the DownloadManager, and launch a new intent with the Adobe Reader to display the file. It works fine, except that when the Adobe Reader starts, it displays the following message prior to displaying the actual file:

Read-only document | To modify this document save a copy on your device. Save | View Read-only

After I dismiss this prompt, the document gets displayed correctly. How can I get rid of the Read-only prompt?

Here is my code:

public class MyDownloadListener implements DownloadListener {

    MainActivity activity;
    BroadcastReceiver receiver;
    DownloadManager downloadManager;

    public MyDownloadListener(MainActivity a) {
        activity = a;
        downloadManager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
        receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                    long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                    Query query = new Query();
                    query.setFilterById(downloadId);
                    Cursor c = downloadManager.query(query);
                    if (c.moveToFirst()) {
                        int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                        if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                            String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
                            File fileSrc = new File(uriString);
                            Intent intentPdf = new Intent(Intent.ACTION_VIEW);
                            intentPdf.setDataAndType(Uri.fromFile(fileSrc), "application/pdf");
                            intentPdf.setPackage("com.adobe.reader");
                            intentPdf.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            activity.startActivity(intentPdf);
                        }
                    }
                }
            }
        };
        activity.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    }

    @Override
    public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
        Request request = new Request(Uri.parse(url));
        downloadManager.enqueue(request);
    }
}
mschuster
  • 191
  • 2
  • 8

1 Answers1

0

As per the official documentation of class DownloadManager.Request

This class contains all the information necessary to request a new download. The URI is the only required parameter. Note that the default download destination is a shared volume where the system might delete your file if it needs to reclaim space for system use. If this is a problem, use a location on external storage (see setDestinationUri(Uri).

So default location is more of a cache location and system can delete the file if it require more space. So if you want to kep the file then you can use setDestinationUri to provide the path in the SD card..

And it looks like the default space does not allow any other thread/process other then the download manager to write file in that space, hence the read only message from the adobe reader..

Praful Bhatnagar
  • 7,425
  • 2
  • 36
  • 44
  • There is no problem with the system deleting the file once it is not needed. Actually, this is a fairly desirable action, so that the file does not take up space for ever. And there should be no problem with the read-only file access either. I do not want to modify the file, I only want to view it. – mschuster Apr 12 '13 at 08:40
  • oh.. in this case can you try to save the file in cache directory.. http://developer.android.com/reference/android/content/Context.html#getCacheDir().. just to see if the read only message is gone.. – Praful Bhatnagar Apr 12 '13 at 08:42