0

我必须使用phonegap在android中打开pdf文件。我在 iOS 中尝试过,它工作正常,但在 android 设备上不能使用相同的代码

以下是在 iOS 上运行良好的代码

function Application() {
}
Application.prototype.Run = function() {
    if (device.uuid == "e0101010d38bde8e6740011221af335301010333" || device.uuid == "e0908060g38bde8e6740011221af335301010333") {
        alert("Not Supported in Simulator.");
    }
    else {
        var infoDiv = document.getElementById("infoField");
        var path = this.getWorkingFolder().replace('http://', 'file://') + "sample.pdf";
        infoDiv.innerText = path;

        if (device.platform === 'Android') {
            window.open(path, '_system');
        }
        else {
            window.open(path, '_blank');
        }
    }
}

Application.prototype.getWorkingFolder = function() {
    var path = window.location.href.replace('index.html', '');
    return path;
}
function onDeviceReady() {
    alert('OnDevice Ready called');
    //navigator.splashscreen.hide();
    document.getElementById('btnOpenPDF').onclick = function() {
        var app = new Application();
        app.Run();
    }
}
document.addEventListener("deviceready", onDeviceReady, false);
4

0 回答 0