我正在构建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
。
感谢您的帮助。
答案 0 :(得分:0)
解决方案很简单。
我只是改变了
String index = "/data/data/com.my.wrapper/files/#"
到
String index = "/data/data/com.my.wrapper/files/index.html"