![](/img/trans.png)
[英]navigator.getUserMedia not working on Android / Chrome
[英]Navigator.getUserMedia() returns permission denied when run on android phone
我正在嘗試使用Web API在Android 6.0.0上啟動相機。 下面是在Web瀏覽器上完美運行的代碼段。
var constraints = {
video: true,
audio: false,
}
// get the media sources
MediaStreamTrack.getSources(function(sourceInfos) {
navigator.getUserMedia( constraints, function(stream){
domElement.src = URL.createObjectURL(stream);
}, function(error) {
console.error("Cant getUserMedia()! due to ", error);
});
});
我已將這段代碼捆綁到帶有離子框架的apk中。 但在手機上,它會顯示損壞的視頻播放圖像。
在進一步調試時,我注意到“權限被拒絕”錯誤被拋出。 我不確定這個錯誤被拋出的原因。 我用Google搜索並完成了提供的所有解決方案。 但它對我沒用。
如果我嘗試通過phoneGap構建它,它會顯示NavigatorUserMediaError {name:“PermissionDeniedError”,消息:“只允許安全來源(參見:某些URL)。”,constraintName:“”}
請你幫助我好嗎?
請試試這個答案。
http://api.phonegap.com/1.0/camera
示例用法
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.phonegap.example"
versionCode = "10"
version = "1.0.0" >
<!-- versionCode is optional and Android only -->
<name>PhoneGap Example</name>
<description>
An example for phonegap build docs.
</description>
<author href="https://build.phonegap.com" email="support@phonegap.com">
Hardeep Shoker
</author>
<!--
If you do not want any permissions to be added to your app, add the
following tag to your config.xml; you will still have the INTERNET
permission on your app, which PhoneGap requires.
-->
<preference name="permissions" value="none"/>
<!-- to enable individual permissions use the following examples -->
<feature name="http://api.phonegap.com/1.0/battery"/>
<feature name="http://api.phonegap.com/1.0/camera"/>
<feature name="http://api.phonegap.com/1.0/contacts"/>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/media"/>
<feature name="http://api.phonegap.com/1.0/network"/>
<feature name="http://api.phonegap.com/1.0/notification"/>
</widget>
也許你有Android運行時權限的問題。 在這里,您可以在Ionic中進行討論。 此問題以不明顯的方式發生,但都存在於Android 6運行時權限系統中 。 您可以通過向清單添加權限並請求運行時權限來解決此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.