我有一个Ionic项目,我安装了这个插件来扫描qrcodes:
cordova plugin add https://github.com/wildabeast/BarcodeScanner.git
但是当我使用Android 6.0在samsung s5设备上运行应用程序时,我收到了一个相机错误:
" 抱歉,Android相机遇到了问题。您可能需要重启设备"
有关导致此问题的原因的任何想法?
我测试过:
ionic run android -l -c
ionic run android
这是我按下按钮时执行的代码:
$scope.scanBarcode = function() {
$ionicPlatform.ready(function() {
$cordovaBarcodeScanner.scan().then(function(imageData) {
console.log("Barcode text -> " + imageData.text);
console.log("Barcode Format -> " + imageData.format);
console.log("Cancelled -> " + imageData.cancelled); // prints: cancelled
}, function(error) {
console.log("An error happened -> " + error);
});
});
};
答案 0 :(得分:2)
对于此问题,您可以尝试以下任一解决方案:
1)这是android 6的权限问题。所以修复问题配置平台到android 5.0。
如果您使用MI note 4,则可以尝试以下附加步骤:
MIUI secruity系统需要另一个权限,启用后,相机开始工作
以下是更新设置可以遵循的步骤:
1)转到安检。
2)单击“权限”,然后再次选择“权限”
3)现在从列表中单击“相机”
4)它将列出所有安装的应用程序。查找您的应用并启用权限。
Reff:http://sforsuresh.in/cordova-sorry-android-camera-encountered-problem/
答案 1 :(得分:1)
这就解决了我的问题,在" android"中的config.xml文件中解决了我的问题。平台部分我把:
<platform name="android">
<preference name="android-targetSdkVersion" value="22"/>
</platform>