我正在构建一个Ionic
应用程序,我需要将它打包成一个自定义的Android wrapper
. 基本上,它是一个简单的WebView
链接到下载器。每次可能时,应用程序都会检查是否有任何更新并将其下载Ionic souces
到本地目录。
下载器运行良好,但是当我需要将本地网站加载到WebView
. 到目前为止,这是我的代码:
WebSettings webSettings = webview.getSettings();
webSettings.setDatabaseEnabled(true);
webSettings.setGeolocationEnabled(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportMultipleWindows(false);
webSettings.setRenderPriority(RenderPriority.HIGH);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
{
webSettings.setDatabasePath(getFilesDir().getPath() + "databases/");
}
if (Build.VERSION.SDK_INT >= 11)
{
webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
// Attach listeners
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (Uri.parse(url).getHost().contains(Constants.END_POINT) || Uri.parse(url).getScheme().contains("file")) return false;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
@Override
public void onPageFinished(WebView view, String url)
{
super.onPageFinished(view, url);
layout_progress.setVisibility(View.GONE);
webview.setVisibility(View.VISIBLE);
}
});
webview.setWebChromeClient(new WebChromeClient() {
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback)
{
callback.invoke(origin, true, false);
}
});
// Attach javascript interface
webview.addJavascriptInterface(new WrapperJSInterface(this, webview), "Wrapper");
// Load index
String index = "/data/data/com.my.wrapper/files/#"
webview.loadUrl("file://" + index);
加载到白页,WebView
但会引发一些错误,如下所示:
12-01 15:26:47.793: E/Web Console(8931): Uncaught ReferenceError: start is not defined at file:///data/data/com.my.wrapper/files/#/app/feed:1
12-01 15:26:47.808: E/Web Console(8931): Uncaught ReferenceError: addRow is not defined at file:///data/data/com.my.wrapper/files/#/app/feed:2
12-01 15:26:47.808: E/Web Console(8931): Uncaught ReferenceError: addRow is not defined at file:///data/data/com.my.wrapper/files/#/app/feed:3
12-01 15:26:47.808: E/Web Console(8931): Uncaught ReferenceError: addRow is not defined at file:///data/data/com.my.wrapper/files/#/app/feed:4
12-01 15:26:47.808: E/Web Console(8931): Uncaught ReferenceError: addRow is not defined at file:///data/data/com.my.wrapper/files/#/app/feed:5
12-01 15:26:47.808: E/Web Console(8931): Uncaught ReferenceError: addRow is not defined at file:///data/data/com.my.wrapper/files/#/app/feed:6
我调查过,发现有些人遇到了同样的问题。但我无法修复它。 http://forum.ionicframework.com/t/uncaught-referenceerror-addrow-is-not-defined/9266
如果这有帮助,我不会以Cordova
任何方式使用。
谢谢你的帮助。