I want to develop Android through cordova webview on the web made with HTML. However, cordova is not allowed in navigator.getusermedia. Is there a way?
答案 0 :(得分:0)
您可以通过cordova-diagnostic-plugin
请求使用相机的运行时权限cordova plugin add cordova.plugins.diagnostic
cordova plugin add cordova-custom-config
为config.xml添加相机权限的清单条目(请参阅Android permissions):
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.CAMERA" />
</config-file>
</platform>
Request camera authorization在运行时:
document.addEventListener('deviceready', function(){
cordova.plugins.diagnostic.requestCameraAuthorization(
function(status){
if(status == cordova.plugins.diagnostic.permissionStatus.GRANTED){
// permission granted - use camera
var video = document.querySelector('video');
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true, video: true}, function(stream) {
video.src = window.URL.createObjectURL(stream);
}, function(e){
console.log("Error:" + e);
});
} else {
console.log("No media available");
}
}else{
// permission denied - inform user
}
}, function(error){
console.error("The following error occurred: "+error);
}, false
);
}, false);