I've been trying to figure out a way to get a local webpage content to load and set the webview html content in native script. I've successfully got it working on the simulator but it doesn't seem to work on the device. I've googled around and most people are saying that I need to locate my html files in the 'Documents' dir of my app, but as far as I can see there is no way to get the files I need there when I deploy the app. Can anyone else shed some light on the ways to get files located in the documents folder of the app on deploy or copying them there at runtime. Thank you
var createViewModel = require("./main-view-model").createViewModel;
var orientationModule = require("nativescript-screen-orientation");
var fs = require("file-system");
var webViewInterfaceModule = require('nativescript-webview-interface');
var oWebViewInterface;
var page;
function pageLoaded(){
setupWebViewInterface(page);
// orientationModule.setCurrentOrientation("landscape", function(){
// //console.log("landscape orientation set");
// });
}
// Initializes plugin with a webView
function setupWebViewInterface(page){
var webView = page.getViewById('webView');
var documents = fs.knownFolders;
oWebViewInterface = new webViewInterfaceModule.WebViewInterface(webView, documents.currentApp().path + '/htllo/index.html');
}
function navigatingTo(args) {
page = args.object;
page.bindingContext = createViewModel();
}
exports.pageLoad = pageLoaded;
exports.navigatingTo = navigatingTo;
Documentsfolder you should use native code. Here you will find a example - github.com/tsonevn/ReadFilesFromDevice/blob/master/app/…, how to do that. Regarding to your question you should setDIRECTORY_DOCUMENTSingetExternalStoragePublicDirectorymethod instead ofDIRECTORY_DOWNLOADS. For further info, which directories you could access in Android you could review the article here - developer.android.com/reference/android/os/Environment.html.Documentsdir. You could review the example in the answer, where has been shown how to load WebVew src from local file.