Status: Open
Status: Answered
Status: Closed
Status: Duplicate

Can I View File on my device (Android, iOS)?

Posted Jun 25 by Vladimir Komov.


I have some problem.

So, I developed simple application for AppWorks.

Application can download file (pdf, doc, docx and etc) form Content Server 10.0 on my device.
Then I can view file in my device without internet.

For view file I use this code:

function doOpen(url, target, params, numExpectedRedirects) {

numExpectedRedirects = numExpectedRedirects || 0;
var iab =, target, params);
if (!iab) {
    alert(' returned ' + iab);
var counts;
var lastLoadStartURL;
var wasReset = false;
function reset()  {
    counts = {
        'loaderror': 0,
        'loadstart': 0,
        'loadstop': 0,
        'exit': 0
    lastLoadStartURL = '';

function logEvent(e) {
    console.log('IAB event=' + JSON.stringify(e));
    // Verify that event.url gets updated on redirects.
    if (e.type == 'loadstart') {
        if (e.url == lastLoadStartURL) {
            alert('Unexpected: loadstart fired multiple times for the same URL.');
        lastLoadStartURL = e.url;
    // Verify the right number of loadstart events were fired.
    if (e.type == 'loadstop' || e.type == 'loaderror') {
        if (e.url != lastLoadStartURL) {
            alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url');
        if (numExpectedRedirects === 0 && counts['loadstart'] !== 1) {
            // Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL).
            if (!(e.type == 'loaderror' && counts['loadstart'] === 0)) {
                alert('Unexpected: got multiple loadstart events. (' + counts['loadstart'] + ')');
        } else if (numExpectedRedirects > 0 && counts['loadstart'] < (numExpectedRedirects+1)) {
            alert('Unexpected: should have got at least ' + (numExpectedRedirects+1) + ' loadstart events, but got ' + counts['loadstart']);
        wasReset = true;
        numExpectedRedirects = 0;
    // Verify that loadend / loaderror was called.
    if (e.type == 'exit') {
        var numStopEvents = counts['loadstop'] + counts['loaderror'];
        if (numStopEvents === 0 && !wasReset) {
            alert('Unexpected: browser closed without a loadstop or loaderror.')
        } else if (numStopEvents > 1) {
            alert('Unexpected: got multiple loadstop/loaderror events.');
iab.addEventListener('loaderror', logEvent, false);
iab.addEventListener('loadstart', logEvent, false);
iab.addEventListener('loadstop', logEvent, false);
iab.addEventListener('exit', logEvent, false);

return iab;}

for Iphone

url = "/var/…../Documents/…downloads/file.pdf"

for Andriod

url = "../sdcard/…/downloads/file.pdf"

This is code InAppBrowser by cordova
link on developer opentext com

On iPhone all documents open very well, but on Android do nothing.
Open browser, in address field typed true url, but file do not show (or load)
Help me to view file on my Andriod device!!!
enter image description here

6 Answers

BEST ANSWER: As chosen by the author.

hi Vladimir,

Is there any error message produced in the Android device console?
Is the path correct? the default is Download folder instead of downloads. Maybe that causes the issue…

Here's some working example

BEST ANSWER: As chosen by the author.

Thanks, Marcin.
Your solution better my.
But problem has not solved.

my code:

var downloadURL = "file:///storage/sdcard0/downloads/file.pdf"; [for Android]
var downloadURL = "file:///var/mobile/Application/...bla-bla-bla.../downloads/file.pdf"; [for iOS]

    // Invoke the cordova plugin to download and display the file
    cordova.exec(content.api.viewSuccess, content.api.viewFail, "Download", "downloadAndDisplayFile", [downloadURL]);

on iOS file view very good.

on Android - "Error, This file cannot be opened for viewing."

Why Android can not view file? I paused in perplexity.


I create folder "downloads". It is not default folder.

BEST ANSWER: As chosen by the author.

It's difficult to say what's going wrong. Are you able to open the file on a device via File Manager?

BEST ANSWER: As chosen by the author.

Yes. I can open the file on a device via File Manager

BEST ANSWER: As chosen by the author.

Error when a try view file:

java.lang.ClassCastException: cannot be cast to

BEST ANSWER: As chosen by the author.

Hi Vladimir,

did you resolve the issue? It seems I am facing same thing.


 You have subscribed and will receive email notifications of updates to this topic. To unsubscribe, uncheck the checkbox.


Related categories

Related tags

Your answer

To leave an answer, please sign in.