【问题标题】:Not able to open the camera from the WebView in appcelerator无法从 appcelerator 中的 WebView 打开相机
【发布时间】:2016-02-17 19:31:33
【问题描述】:

目前我正在努力在 webview 中加载一个 url,通过在浏览器中使用相同的 url,它能够“通过显示访问相机的警报”来访问相机,但是当我在 webview 中使用相同的 url 时appcelerator 的应用程序无法访问相机。如果指导我解决这个问题。

提前致谢。

【问题讨论】:

    标签: javascript android webview appcelerator appcelerator-titanium


    【解决方案1】:

    您可以从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

    【讨论】:

    • 嗨 abada 感谢您的建议,但我不是那个意思。我正在使用企业网址。当我在浏览器中点击该 url 时,它要求访问访问相机的权限,但是当我在 webview 中使用该 url 时,它无法访问相机,显示视频已禁用。
    • 你能写下这个网址吗?
    • @SauravSenapati 所以看起来 WebView 可以请求(HTML5)设备权限,但不知何故没有得到它们。这看起来像一个错误。请通过Appcelerator JIRA 检查这是否是一个已知问题。如果不是,请创建票证,链接到此问题,但还要在票证本身中提供可重现的代码、步骤和环境信息。不要忘记在此处放置门票链接,以便其他人可以与您一起观看。
    猜你喜欢
    • 1970-01-01
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 2022-07-21
    • 2018-01-24
    • 1970-01-01
    相关资源
    最近更新 更多