起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8292|回复: 15

[处理中3] 华为安卓7.0的手机拍照和相册、录像都有问题

[复制链接]

14

主题

55

帖子

205

积分

中级会员

Rank: 3Rank: 3

积分
205
QQ
发表于 2017-8-18 15:38:59 | 显示全部楼层 |阅读模式
1、第一次安装成功,没有读取存储的权限。直接点击相册闪退。如果先点击相机,会提示是否允许存储权限,允许后在点击相册,正常。
2、华为P9、P9 PLUS使用相机,拍照后进入失败的回调。提示error capturing image 或者 index=1,length=1
三星安卓7.0也有部分手机有类似的问题。

之前看过一个帖子说/Native/templates/advanced/platforms/android 修改模版文件可以解决1的问题,是否可以提供一个模版的文件修改的例子
发表于 2017-8-18 16:19:34 | 显示全部楼层
qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

14

主题

55

帖子

205

积分

中级会员

Rank: 3Rank: 3

积分
205
QQ
 楼主| 发表于 2017-8-18 17:57:03 | 显示全部楼层
liangyongfei 发表于 2017-8-18 16:19
http://bbs.wex5.com/forum.php?mod=redirect&goto=findpost&ptid=176346&pid=165474010

这个解决了相机拍照的问题。
相册的问题还是没解决,用的是com.synconset.imagepicker插件,直接闪退
还有录像,点击没有反应,用的是cordova-plugin-media-capture插件
回复 支持 反对

使用道具 举报

14

主题

55

帖子

205

积分

中级会员

Rank: 3Rank: 3

积分
205
QQ
 楼主| 发表于 2017-8-18 17:58:24 | 显示全部楼层
本帖最后由 eye215 于 2017-8-18 18:26 编辑

JS完整代码
  1. define(function(require) {
  2.         var $ = require("jquery");
  3.         var justep = require("$UI/system/lib/justep");
  4.         require("$UI/system/lib/cordova/cordova");
  5.         require("cordova!cordova-plugin-camera"); // 相机
  6.         require("cordova!cordova-plugin-file");
  7.         require("cordova!cordova-plugin-inappbrowser");
  8.         require("cordova!com.synconset.imagepicker");
  9.         require("cordova!cordova-plugin-media-capture");
  10.         require("cordova!cordova-plugin-streaming-media"); // 视频播放

  11.         var Model = function() {
  12.                 this.callParent();
  13.         };

  14.         // 拍照
  15.         Model.prototype.onCamera = function(event) {
  16.                 var self = this;
  17.                 if (!navigator.camera) {
  18.                         return false;
  19.                 }
  20.                 var fileData = self.comp("fileData");
  21.                 if (fileData.count >= 9) {
  22.                         justep.Util.hint("只能上传9张图片!", {
  23.                                 "type" : "danger",
  24.                                 "delay" : 1000,
  25.                                 "position" : "middle"
  26.                         });
  27.                         return;
  28.                 }
  29.                 function onSuccess(imageURI) {
  30.                         self.dealWithPic(imageURI);
  31.                 }
  32.                 function onFail(message) {
  33.                         alert(message);
  34.                 }
  35.                 navigator.camera.getPicture(onSuccess, onFail, {
  36.                         quality : 50,
  37.                         saveToPhotoAlbum : true
  38.                 });
  39.         }
  40.         Model.prototype.onVideo = function(event) {
  41.                 var self = this;
  42.                 var options = {
  43.                         limit : 1,
  44.                         quality : 1,
  45.                         duration : 20
  46.                 };
  47.                 var captureSuccess = function(mediaFiles) {
  48.                         var i, len;
  49.                         var fileData = self.comp("fileData");
  50.                         for (i = 0, len = mediaFiles.length; i < len; i++) {
  51.                                 var mediaFile = mediaFiles[i];
  52.                                 self.video = mediaFile;
  53.                                 var data = {
  54.                                         "fileType" : "video",
  55.                                         "fileInfo" : [ mediaFile ]
  56.                                 }
  57.                                 fileData.loadData([ data ]);
  58.                         }
  59.                 }
  60.                 var captureError = function(){
  61.                         alert('Error: ' + JSON.stringify(error.code));
  62.                 }
  63.                 navigator.device.capture.captureVideo(captureSuccess, captureError, options);
  64.         }

  65.         // 相册
  66.         Model.prototype.onPhotos = function(event) {
  67.                 var self = this;
  68.                 if (!navigator.camera) {
  69.                         return false;
  70.                 }
  71.                 var fileData = self.comp("fileData");
  72.                 if (fileData.count >= 9) {
  73.                         justep.Util.hint("只能上传9张图片!", {
  74.                                 "type" : "danger",
  75.                                 "delay" : 1000,
  76.                                 "position" : "middle"
  77.                         });
  78.                         return;
  79.                 }

  80.                 document.addEventListener("deviceready", onDeviceReady, false);
  81.                 function onDeviceReady() {
  82.                         imagePicker.getPictures(successCallback, errorCallback, {
  83.                                 "maximumImagesCount" : 9,// 最大图片选择数量
  84.                                 "width" : 1000,// 图片的高度和宽度限定,如果都写成0,则按照图片大小显示,不为0且大于该值则进行等比例压缩
  85.                                 "height" : 1000,
  86.                                 "quallity" : 50,// 图片质量,取值为0-100
  87.                                 "outputType" : 0
  88.                         // 导出图片的类型,默认为FILE_URI(实际值为0),BASE64_STRING (实际值为1)
  89.                         });
  90.                 }
  91.                 function successCallback(imageURI) {
  92.                         if (imageURI.length > 0) {
  93.                                 var dfds = [];
  94.                                 for (var i = 0; i < imageURI.length; i++) {
  95.                                         var dfd = self.dealWithPic(imageURI[i]);
  96.                                         dfds.push(dfd);
  97.                                 }

  98.                                 $.when.apply($, dfds).done(function() {
  99.                                         // me.comp("demoPopOver").hide();
  100.                                 });
  101.                         } else {
  102.                                 justep.Util.hint("您未选择图片", {
  103.                                         "type" : "danger",
  104.                                         "delay" : 1000,
  105.                                         "position" : "middle"
  106.                                 });
  107.                         }
  108.                 }
  109.                 function errorCallback(error) {
  110.                         justep.Util.hint("相册照片上传失败");
  111.                 }
  112.         }

  113.         // 删除按钮
  114.         Model.prototype.onFileDel = function(event) {
  115.                 var parentRow = event.bindingContext.$parent;
  116.                 this.comp("fileData").deleteData(parentRow);
  117.         }

  118.         // 播放网络视频
  119.         Model.prototype.onPlay = function(event) {
  120.                 var videoUrl = "http://www.runoob.com/try/demo_source/movie.mp4";// http://vjs.zencdn.net/v/oceans.ogv
  121.                 // Play a video with callbacks
  122.                 var options = {
  123.                         successCallback : function() {
  124.                                 // console.log("Video was closed without error.");
  125.                         },
  126.                         errorCallback : function(errMsg) {
  127.                                 // console.log("Error! " + errMsg);
  128.                         },
  129.                         orientation : 'landscape',
  130.                         shouldAutoClose : false, // true(default)/false
  131.                         controls : true
  132.                 // true(default)/false. Used to hide controls on fullscreen
  133.                 };
  134.                 window.plugins.streamingMedia.playVideo(videoUrl, options);
  135.         }

  136.         // 播放本地视频
  137.         Model.prototype.onLocalPlay = function(event) {
  138.                 var videoUrl = this.video;
  139.                 if (videoUrl == '') {
  140.                         return;
  141.                 }
  142.                 // Play a video with callbacks
  143.                 var options = {
  144.                         successCallback : function() {
  145.                                 // console.log("Video was closed without error.");
  146.                         },
  147.                         errorCallback : function(errMsg) {
  148.                                 // console.log("Error! " + errMsg);
  149.                         },
  150.                         orientation : 'landscape',
  151.                         shouldAutoClose : false, // true(default)/false
  152.                         controls : true
  153.                 // true(default)/false. Used to hide controls on fullscreen
  154.                 };
  155.                 window.plugins.streamingMedia.playVideo(videoUrl.fullPath, options);
  156.         }

  157.         // 获得图片的二进制流
  158.         Model.prototype.dealWithPic = function(imageURI, imgname) {
  159.                 var self = this;
  160.                 var dfd = $.Deferred();

  161.                 window.resolveLocalFileSystemURI(imageURI, function(entry) {
  162.                         entry.file(win, fail);

  163.                         function win(file) {
  164.                                 var reader = new FileReader();
  165.                                 reader.readAsDataURL(file);
  166.                                 // reader.readAsBinaryString(file);
  167.                                 // reader.readAsArrayBuffer(file);

  168.                                 reader.onloadend = function(e) {
  169.                                         var imgUrl = entry.toInternalURL();

  170.                                         var fileData = self.comp("fileData");
  171.                                         var image = {};
  172.                                         image.name = imageURI.substr(imageURI.lastIndexOf('/') + 1);
  173.                                         image.type = 'image/jpeg';
  174.                                         // image.size = '';
  175.                                         image.fullPath = imageURI;
  176.                                         image.src = imgUrl;
  177.                                         fileData.loadData([ {
  178.                                                 "fileType" : "image",
  179.                                                 "fileInfo" : [ image ]
  180.                                         } ], true);
  181.                                 };
  182.                         }

  183.                         var fail = function(evt) {
  184.                                 justep.Util.hint("上传图片失败", {
  185.                                         "type" : "danger",
  186.                                         "delay" : 1000,
  187.                                         "position" : "middle"
  188.                                 });
  189.                         };

  190.                 }, function() {

  191.                 });
  192.                 return dfd.promise();
  193.         };
  194.         return Model;
  195. });
复制代码



回复 支持 反对

使用道具 举报

14

主题

55

帖子

205

积分

中级会员

Rank: 3Rank: 3

积分
205
QQ
 楼主| 发表于 2017-8-18 18:00:05 | 显示全部楼层
html完整代码
  1. <?xml version="1.0" encoding="utf-8"?>

  2. <div xmlns="http://www.w3.org/1999/xhtml" component="$UI/system/components/justep/window/window" design="device:m;"
  3.   xid="window" class="window">  
  4.   <div component="$UI/system/components/justep/model/model" xid="model" style="left:18px;top:83px;height:244px;">
  5.     <div component="$UI/system/components/justep/data/data" xid="fileData"
  6.       idColumn="fileInfo" autoNew="false" autoLoad="true">
  7.       <column name="fileInfo" type="String" xid="fileInfo"/>  
  8.       <column name="fileType" type="String" xid="fileType"/>
  9.     </div>
  10.   </div>  
  11.   <div component="$UI/system/components/justep/panel/panel" class="x-panel x-full"
  12.     xid="panel1">
  13.     <div class="x-panel-top" xid="top1">
  14.       <div component="$UI/system/components/justep/titleBar/titleBar" title="标题"
  15.         class="x-titlebar">
  16.         <div class="x-titlebar-left">
  17.           <a component="$UI/system/components/justep/button/button" label=""
  18.             class="btn btn-link btn-only-icon" icon="icon-chevron-left" onClick="{operation:'window.close'}"
  19.             xid="backBtn">
  20.             <i class="icon-chevron-left"/>  
  21.             <span/>
  22.           </a>
  23.         </div>  
  24.         <div class="x-titlebar-title">标题</div>  
  25.         <div class="x-titlebar-right reverse"/>
  26.       </div>
  27.     </div>  
  28.     <div class="x-panel-content" xid="content1">
  29.       <div class="form">
  30.         <div class="form-group" component="$UI/system/components/bootstrap/form/form"
  31.           xid="xb-form">
  32.           <div class="input-group x-row upload-file-box" xid="uploadFile">
  33.             <div class="x-col" bind-click="onCamera">
  34.               <i class="icon-camera"/> 相机
  35.             </div>  
  36.             <div class="x-col" bind-click="onVideo">
  37.               <i class="icon-videocamera"/> 录像
  38.             </div>  
  39.             <div class="x-col" bind-click="onPhotos">
  40.               <i class="icon-ios7-photos"/> 相册
  41.             </div>  
  42.             <div class="x-col" bind-click="onPlay">
  43.               <i class="icon-play"/> 播放远程视频
  44.             </div>
  45.           </div>  
  46.           <div component="$UI/system/components/justep/list/list" data="fileData"
  47.             class="input-group x-list x-list-template" xid="uploadFileList">
  48.             <div class="file-preview" bind-css="{'video-play':val('fileType')=='video'}"
  49.               bind-foreach="val('fileInfo')">
  50.               <i bind-visible="$parent.val('fileType')=='video'" class="glyphicon glyphicon-play-circle"
  51.                 bind-click="onLocalPlay"/>  
  52.               <img bind-visible="$parent.val('fileType')=='image'" bind-attr-src="$object.src"/>  
  53.               <span class="file-del" bind-click="onFileDel">
  54.                 <i class="icon-close"/>
  55.               </span>
  56.             </div>
  57.           </div>
  58.         </div>
  59.       </div>
  60.     </div>
  61.   </div>
  62. </div>
复制代码


css完整代码
  1. .x-titlebar-right .glyphicon{ color:#fff; font-size:20px; padding:0 10px;}

  2. .input-group{width:90%; margin:auto; padding:10px 0;background:#fff; border-bottom:1px #e9e9e9 solid; }

  3. .upload-file-box{ text-align:center;}
  4. .upload-file-box .x-col{ line-height:30px;}
  5. .upload-file-box i{font-size:24px; color:#ffd51a;vertical-align:middle}
  6. .file-preview{ width:23%;margin:1%; float:left;min-height:75px; height:auto;position:relative}
  7. .file-preview img{ width:100%;}
  8. .file-del{
  9. position: absolute;
  10. top: -5px;
  11. right: -5px;
  12. background-color: rgba(0, 0, 0, 0.2);
  13. /* padding: 5px; */
  14. border-radius: 50%;
  15. height: 20px;
  16. width: 20px;
  17. text-align: center;
  18. line-height: 20px;}
  19. .file-del i{ color:red;}
  20. .video-play{ display:table; text-align:center; background:rgba(0,0,0,.8)}
  21. .video-play .glyphicon{ color:#fff;vertical-align: middle; font-size:24px;
  22. display: table-cell;}
复制代码
回复 支持 反对

使用道具 举报

14

主题

55

帖子

205

积分

中级会员

Rank: 3Rank: 3

积分
205
QQ
 楼主| 发表于 2017-8-18 18:01:27 | 显示全部楼层
测试的手机是华为 P10 PLUS 安卓系统7.0
回复 支持 反对

使用道具 举报

14

主题

55

帖子

205

积分

中级会员

Rank: 3Rank: 3

积分
205
QQ
 楼主| 发表于 2017-8-18 18:05:49 | 显示全部楼层
相册  和 录像 代码里能不能加上判断是否有权限,然后在执行相应的方法?
还是修改一下配置文件就可以了?
回复 支持 反对

使用道具 举报

14

主题

55

帖子

205

积分

中级会员

Rank: 3Rank: 3

积分
205
QQ
 楼主| 发表于 2017-8-18 22:31:04 | 显示全部楼层
liangyongfei 发表于 2017-8-18 16:19
http://bbs.wex5.com/forum.php?mod=redirect&goto=findpost&ptid=176346&pid=165474010

华为荣耀V8 安卓系统6.0、华为P9 安卓系统6.0、6.0.1 使用相机拍照后确认调用失败返回:error capturing image 。
有部分手机如果相册是空的,拍照成功后调用失败返回:error capturing image。使用手机的相机app拍照之后,再使用wex5app拍照成功。 手机相册如果是空的,那么点击相册也是闪退。

小米   MI MAX 安卓系统6.0,第一次使用相册闪退,使用相机允许权限之后,再使用相册成功。

三星 Note 5 安卓系统6.0。1    三星S8 安卓7.0   三星s8+安卓7.0   都有类似的问题。
回复 支持 反对

使用道具 举报

34

主题

66

帖子

182

积分

初级会员

Rank: 2

积分
182
QQ
发表于 2017-8-21 16:55:24 | 显示全部楼层
eye215 发表于 2017-8-18 22:31
华为荣耀V8 安卓系统6.0、华为P9 安卓系统6.0、6.0.1 使用相机拍照后确认调用失败返回:error capturing  ...

你好,我是刚学这个的新手,现在要做一个发视频的功能,类似于微信朋友圈的功能,视频这块不太会弄,能不能分享一点案列啊,希望你帮帮忙
回复 支持 反对

使用道具 举报

14

主题

55

帖子

205

积分

中级会员

Rank: 3Rank: 3

积分
205
QQ
 楼主| 发表于 2017-8-21 17:43:53 | 显示全部楼层
田健 发表于 2017-8-21 16:55
你好,我是刚学这个的新手,现在要做一个发视频的功能,类似于微信朋友圈的功能,视频这块不太会弄,能不 ...

复制上面的代码  就可以在安卓6.0以下的系统实现,具体的逻辑需要修改js实现。
还有安卓6.0以上的系统还有问题,苹果系统还没测试。
视频太大的问题还没解决。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-5-1 08:13 , Processed in 0.116858 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表