【发布时间】:2016-02-17 19:31:33
【问题描述】:
目前我正在努力在 webview 中加载一个 url,通过在浏览器中使用相同的 url,它能够“通过显示访问相机的警报”来访问相机,但是当我在 webview 中使用相同的 url 时appcelerator 的应用程序无法访问相机。如果指导我解决这个问题。
提前致谢。
【问题讨论】:
标签: javascript android webview appcelerator appcelerator-titanium
目前我正在努力在 webview 中加载一个 url,通过在浏览器中使用相同的 url,它能够“通过显示访问相机的警报”来访问相机,但是当我在 webview 中使用相同的 url 时appcelerator 的应用程序无法访问相机。如果指导我解决这个问题。
提前致谢。
【问题讨论】:
标签: javascript android webview appcelerator appcelerator-titanium
您可以从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
【讨论】: