无法从应用器中的 Web 视图打开相机

Not able to open the camera from the WebView in appcelerator

本文关键字:视图 Web 相机 应用      更新时间:2023-09-26

目前我正在 Web 视图中加载一个 URL,通过在浏览器中使用相同的 URL,它能够"通过显示访问相机的警报"来访问相机,但是当我在应用程序中的 Web 视图中使用相同的 URL 时,Appcelerator 无法访问相机。如果指导我解决这个问题.

提前谢谢.

您可以从webview触发 Ti 事件,并在事件侦听器内部访问摄像机

前任:-

网页视图文件

<html>
    <head>
        <script>
            Ti.App.addEventListener("app:fromTitanium", function(e) {
                alert(e.message);
            });
        </script>
    </head>
    <body>
        <button onclick="Ti.App.fireEvent('app:fromWebView', { message: 'event fired from WebView, handled in Titanium' });">fromWebView</button>
    </body>
</html>

Js 文件

var win = Ti.UI.createWindow();
var webview = Ti.UI.createWebView({
    url: 'logging.html'
});
var button = Ti.UI.createButton({
    title: 'fromTitanium',
    height: '50dp',
    width: '130dp'
});
button.addEventListener('click', function(e) {
    Ti.App.fireEvent('app:fromTitanium', { message: 'event fired from Titanium, handled in WebView' });
});
Ti.App.addEventListener('app:fromWebView', function(e) {
    alert(e.message);
});
win.add(webview);
win.add(button);
win.open();

更多详情 http://docs.appcelerator.com/platform/latest/#!/guide/Communication_Between_WebViews_and_Titanium