android - 如何在 webview 中使用相机反应原生?
问题描述
我正在尝试从反应原生的 web 视图中捕获图像,然后在我的 html 页面上显示相同的图像。
问题:我无法从 webview 访问相机和保存图像。
解决方案:我正在使用 react-native-camera 捕获和保存图像。
下一个问题:我想在我的 webview 中显示上面保存的图像,然后将其保存在服务器上。
注意:当我在浏览器中打开页面时,我的页面能够捕获并保存在服务器上的数据。我对本机反应中的 webview 很感兴趣。
mywebview.js 文件
import React from 'react';
import { StyleSheet, View, WebView, ActivityIndicator } from 'react-native';
const HtmlPage = require('./index.html');
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center'
},
horizontal: {
flexDirection: 'row',
justifyContent: 'space-around',
padding: 10
}
})
class WebViewScreen extends React.Component {
webView = {
canGoBack: false,
ref: null,
postMessage: function () { }
}
renderLoading() {
return (<View style={[styles.container, styles.horizontal]}>
<ActivityIndicator size="large" color="#0000ff" />
<ActivityIndicator size="small" color="#00ff00" />
<ActivityIndicator size="large" color="#0000ff" />
<ActivityIndicator size="small" color="#00ff00" />
</View>);
}
render() {
return (
<WebView
//source={{uri:uri_source}}
source={HtmlPage}
style={{ marginTop: 2 }}
onMessage={this.msgHandler.bind(this)}
domStorageEnabled={true}
ref={(webView) => { this.webView.ref = webView; }}
renderLoading={this.renderLoading.bind(this)}
startInLoadingState
/>
);
}
}
export default WebViewScreen
index.html 文件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Native Boiler</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<p>Hi from html 5</p>
<img src="file:///data/user/0/com.awesomeproject/files/pic.jpg" alt="Smiley face" height="42" width="42">
</body>
</html>
解决方案
推荐阅读
- r - 我的 kable 表不会导出为图像
- python - Python tkinter:创建和控制许多小部件
- swift - Switch Case 处理两种不同的场景
- python - 使用 PyInstaller noconsole 显示标准输出
- wordpress - 在 Woocommerce 中的摘要电子邮件中对齐 address_1 和 address_2 字段内容
- python - 如何避免在可以做多和做空的交易策略中重复代码
- single-sign-on - 是否有用于在 InfusionSoft 和 react/django Web 应用程序之间设置 SSO 的 SSO 选项?
- network-programming - 如何在 NVIDIA Bluefield SmartNIC 上运行代码?
- php - PHP上传数组偏移问题
- python - 修改@abstractmethod 中的变量,从而在继承的方法上反映相同的变量