android - Phonegap - 从外部网站访问 api

标签 android cordova webview phonegap-build

我在配置文件中设置:

<access origin="*" subdomains="true" />
<access origin=".*" subdomains="true" />
<content src="http://mydomain.pl/aps_mobile/" />

但是在 http://mydomain.pl/aps_mobile/不执行事件“deviceready”并且 navigator.camera 未定义。 我做错了什么?

最佳答案

如果从外部主机执行cordova脚本,您将无法访问硬件资源,因为该脚本未映射到Phonegap应用程序的libs/cordova.x.x.x.jar。 但你可以这样解决:

在 res/xml/config.xml 中

<access origin="*" />
<content src="index.html" />

在 Assets /www/index.html

<body>
    <script type="text/javascript" src="cordova-x.x.x.js"></script>
    <iframe name="framewrap" id="framewrap"
        style="border:0;position: absolute; top: 0; left: 0;width: 100%;"
        src="http://yourwebsite.pl">
    </iframe>
    <script type="text/javascript"> 
        document.getElementById("framewrap").contentWindow.navigator = navigator;
    </script>
 </body>

最后,在相机配置中,如果您想要 DATA_URL,则必须将destinationType 设置为 0;如果您想要 FILE_URI,则必须将destinationType 设置为 1;如果您想要 NATIVE_URI,则必须将destinationType 设置为 2。

希望对你有帮助

关于android - Phonegap - 从外部网站访问 api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16064142/

相关文章:

android - 通过 LocalSocket 从 MediaRecorder 流式传输视频

ios - Cordova 中的 Google 标签管理器插件中的问题

html - 如何让 webview 只加载特定的网站,比如 youtube?

android - TabLayout 上方的页眉布局

android - 在代码中向 ListView 添加页脚

iphone - 移动开发分发

javascript - this.platform.is ("mobile") 为浏览器返回 true

cordova - 是否可以播放多个内嵌视频

javascript - Android : Detect history. WebView 中的 back()

java - 在 WebView android 中单击链接时显示 pdf