允许在HTML5 Phonegapped Android应用程序开放的本地文件 [英] Allow opening of local files in HTML5 Phonegapped Android app

查看:122
本文介绍了允许在HTML5 Phonegapped Android应用程序开放的本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML5应用程序。其中正常运行在浏览器中。而罚款时,结束了作为一个iOS应用程序。 然而,当我打造为Android,我通过ADB调试时收到以下消息。

I have a HTML5 app. Which runs fine in a browser. And fine when wrapped up as an iOS app. However when I build for Android I am getting the following message when debugging through adb.

XMLHttpRequest cannot load file:///android_asset/www/data/translations.json. Origin null is not allowed by Access-Control-Allow-Origin. at null:1

这时候我打电话尝试加载与 $文件时发生。的getJSON

This occurs when I call try to load the file with $.getJSON

显然,这可以用Java解决了与

Apparently this can be resolved in JAVA with

if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
  webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
}

不过,我需要一种方法来做到这一点的HTML5应用程序包与PhoneGap的。我怎样才能开启此设置?

However, I need a way to do this in a HTML5 app wrapped up with phonegap. How can I turn this setting on?

推荐答案

更​​新到最新(在发布2.8.1的时间)科尔多瓦瓶解决了问题。

Updating to the lastest (at time of posting 2.8.1) cordova jar resolved the issue.

这篇关于允许在HTML5 Phonegapped Android应用程序开放的本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆