开发当中碰到一个问题 plus.gallery.save一直失败,后来发现是手机设置当中相册的访问权限问题
//html
<img src="">
<div id="picture" class="mui-popover mui-popover-action mui-popover-bottom" style="z-index: 99999999"><ul class="mui-table-view"><li class="mui-table-view-cell"><a href="javascript:;" id="saveImg">保存图片</a></li></ul><ul></ul><ul class="mui-table-view"><li class="mui-table-view-cell"><a href="#picture"><b>取消</b></a></li></ul></div>//js
mui.init( { gestureConfig:{tap: true, //默认为truedoubletap: true, //默认为falselongtap: true, //默认为falseswipe: true, //默认为truedrag: true, //默认为truehold:true,//默认为false,不监听release:false//默认为false,不监听}})
//给需要长按保存图片的img标签设置 class='saveImg'mui.plusReady(function(){var divs = document.getElementsByTagName('img');for(var i = 0;i<divs.length;i++){divs[i].addEventListener('longtap', function () {//开启弹框mui('#picture').popover('toggle');var imgurl = this.src;document.getElementById('saveImg').addEventListener('tap', function () {save___img(imgurl)});})}});function save___img(picurl) { 直接获取src 不管是否是base64 安卓需要图片地址 base64保存不了// 创建下载任务// picurl="http://photocdn.sohu.com/20120708/Img347586958.jpg";//图片保存到手机后的路径// picname="_downloads/"+randomString(16)+".png";plus.nativeUI.showWaiting('加载中...');var dtask = plus.downloader.createDownload(picurl, {}, function ( d, status ) {// 下载完成if ( status == 200 ) { // alert( "Download success: " + d.filename );plus.gallery.save(d.filename,function() {//保存到相册方法plus.nativeUI.closeWaiting();mui.toast('已保存到手机相册');}, function() {plus.nativeUI.closeWaiting();mui.toast('保存失败,请重试!');});} else {// alert( "Download failed: " + status ); mui.toast("下载失败");}});//dtask.addEventListener( "statechanged", onStateChanged, false );dtask.start();//开始下载
}