android phonegap/cordova change property on webview

江枫思渺然 提交于 2020-01-06 04:31:22

问题


In the past, I have changed a normal Webview property on Android. For example:

wv.getSettings().setAllowUniversalAccessFromFileURLs(true);

where wv is a variable of webview. Now, I have an phonegap/cordova app, and I want to change the same line of code, I have been trying the the following way:

super.appView.getSettings().setAllowUniversalAccessFromFileURLs(true);

and also like:

super.appView.getSettings().setAllowUniversalAccessFromFileURLs(true);

I don't get any compiling errors, but when I add that line of code on the onCreate method, the app just closes. I have been trying to add the line on the onCreate method at different places, like, before and after the super.onCreate and before and after loading the html (super.loadUrl("file:///android_asset/www/index.html"), but the app always closes. Any of you know if it is possible to change that property on phonegap/cordova ?


回答1:


That code is already in our web view so you don't need to set it. Probably the reason it is crashing is that you are not running on an ICS device. That method is only available in ICS or better.

If you really want to add it do:

if(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        super.appView.getSettings().setAllowUniversalAccessFromFileURLs(true);
}


来源:https://stackoverflow.com/questions/12016286/android-phonegap-cordova-change-property-on-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!