Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将本机应用程序与worklight项目相结合_Android_Ibm Mobilefirst - Fatal编程技术网

Android 将本机应用程序与worklight项目相结合

Android 将本机应用程序与worklight项目相结合,android,ibm-mobilefirst,Android,Ibm Mobilefirst,我正在开发一个worklight应用程序,其中需要文件IO。我已经在一个android项目中分别编写了这些代码。有人能告诉我如何将两者结合成一个整体吗 无法将现有Worklight混合应用程序与现有本机应用程序组合。Worklight应用程序的正确方法是编写一个Cordova插件,在本机端执行您想要的操作 请参阅这些培训模块,其中解释了如何做到这一点:无法将现有Worklight混合应用程序与现有本机应用程序相结合。Worklight应用程序的正确方法是编写一个Cordova插件,在本机端执行您

我正在开发一个worklight应用程序,其中需要文件IO。我已经在一个android项目中分别编写了这些代码。有人能告诉我如何将两者结合成一个整体吗

无法将现有Worklight混合应用程序与现有本机应用程序组合。Worklight应用程序的正确方法是编写一个Cordova插件,在本机端执行您想要的操作


请参阅这些培训模块,其中解释了如何做到这一点:

无法将现有Worklight混合应用程序与现有本机应用程序相结合。Worklight应用程序的正确方法是编写一个Cordova插件,在本机端执行您想要的操作


请参阅这些培训模块,其中解释了如何做到这一点:

正如Idan所说,无法将现有的本机应用程序移植到Worklight混合应用程序。不过,您可以利用Worklight混合应用程序在不同环境(如Android和iOS)中开箱即用的优势。如果您创建了一个插件,则需要为您希望支持的所有环境创建一个插件

下面是一个文件I/O API的快速示例:

下面是一个文件示例:


正如Idan所说,无法将现有本机应用程序移植到Worklight混合应用程序。不过,您可以利用Worklight混合应用程序在不同环境(如Android和iOS)中开箱即用的优势。如果您创建了一个插件,则需要为您希望支持的所有环境创建一个插件

下面是一个文件I/O API的快速示例:

下面是一个文件示例:

// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is ready
//
function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
    fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);
}

function gotFileEntry(fileEntry) {
    fileEntry.createWriter(gotFileWriter, fail);
}

function gotFileWriter(writer) {
    writer.onwriteend = function(evt) {
        console.log("contents of file now 'some sample text'");
        writer.truncate(11);  
        writer.onwriteend = function(evt) {
            console.log("contents of file now 'some sample'");
            writer.seek(4);
            writer.write(" different text");
            writer.onwriteend = function(evt){
                console.log("contents of file now 'some different text'");
            }
        };
    };
    writer.write("some sample text");
}

function fail(error) {
    console.log(error.code);
}
// Wait for Cordova to load
//
function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

// Cordova is ready
//
function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
    fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
}

function gotFileEntry(fileEntry) {
    fileEntry.file(gotFile, fail);
}

function gotFile(file){
    readDataUrl(file);
    readAsText(file);
}

function readDataUrl(file) {
    var reader = new FileReader();
    reader.onloadend = function(evt) {
        console.log("Read as data URL");
        console.log(evt.target.result);
    };
    reader.readAsDataURL(file);
}

function readAsText(file) {
    var reader = new FileReader();
    reader.onloadend = function(evt) {
        console.log("Read as text");
        console.log(evt.target.result);
    };
    reader.readAsText(file);
}

function fail(evt) {
    console.log(evt.target.error.code);
}