华为机型 cordova-plugin-camera从图库获取报错
来源:互联网 发布:网络用语bgm是什么意思 编辑:程序博客网 时间:2024/05/20 16:13
华为的系统执行如下代码从图库中获取图片会报错.
navigator.camera.getPicture(function(imageURI){alert(imageURI);resolveLocalFileSystemURL(imageURI, function(entry) {alert('cdvfile URI: ' + entry.toInternalURL()); document.querySelector("#aa").src = entry.toInternalURL();//将图片在html img中显示出来});}, function(message){}, { quality: 50, destinationType: Camera.DestinationType.FILE_URI , sourceType:Camera.PictureSourceType.SAVEDPHOTOALBUM}
经过排查发现华为默认的图片浏览返回的是 "com.android.providers.media.documents"
所以要修改 cordova-plugin-camera 插件中的 CameraLauncher.java 文件
增加:
public static boolean isMediaDocument(Uri uri) { return "com.android.providers.media.documents".equals(uri.getAuthority()); } /** * Applies all needed transformation to the image received from the gallery. * * @param destType In which form should we return the image * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ private void processResultFromGallery(int destType, Intent intent) { Uri uri = intent.getData(); if (uri == null) { if (croppedUri != null) { uri = croppedUri; } else { this.failPicture("null data from photo library"); return; } } int rotate = 0; // If you ask for video or all media type you will automatically get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { this.callbackContext.success(uri.toString()); } else { // This is a special case to just return the path as no scaling, // rotating, nor compressing needs to be done if (this.targetHeight == -1 && this.targetWidth == -1 && (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) { if(isMediaDocument(uri)){ String realPath = FileHelper.getRealPath(uri, this.cordova); this.callbackContext.success("file://" + realPath); }else{ this.callbackContext.success(uri.toString()); } } else { String uriString = uri.toString(); // Get the path to the image. Makes loading so much easier. String mimeType = FileHelper.getMimeType(uriString, this.cordova); // If we don't have a valid image so quit. if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retrieve path to picture!"); return; } Bitmap bitmap = null; try { bitmap = getScaledBitmap(uriString); } catch (IOException e) { e.printStackTrace(); } if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (this.correctOrientation) { rotate = getImageOrientation(uri); if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); try { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); this.orientationCorrected = true; } catch (OutOfMemoryError oom) { this.orientationCorrected = false; } } } // If sending base64 image back if (destType == DATA_URL) { this.processPicture(bitmap); } // If sending filename back else if (destType == FILE_URI || destType == NATIVE_URI) { // Did we modify the image? if ( (this.targetHeight > 0 && this.targetWidth > 0) || (this.correctOrientation && this.orientationCorrected) ) { try { String modifiedPath = this.ouputModifiedBitmap(bitmap, uri); // The modified image is cached by the app in order to get around this and not have to delete you // application cache I'm adding the current system time to the end of the file url. this.callbackContext.success("file://" + modifiedPath + "?" + System.currentTimeMillis()); } catch (Exception e) { e.printStackTrace(); this.failPicture("Error retrieving image."); } } else { this.callbackContext.success(uri.toString()); } } if (bitmap != null) { bitmap.recycle(); bitmap = null; } System.gc(); } } }
1 0
- 华为机型 cordova-plugin-camera从图库获取报错
- ionic添加cordova-plugin-camera拍照插件后build报错
- ionic工程引入cordova plugin camera 插件编译报错问题总结
- cordova-plugin-camera及cordova-plugin-crop调用例程
- 从图库获取图片
- cordova-plugin-local-notification在ios平台编译报错
- Ionic安装cordova-plugin-crosswalk-webview报错
- cordova 华为cordova-plugin-image-picker 闪退处理
- Using cordova-camera plugin in your Ionic 2 Apps
- ionic添加调取摄像头插件--cordova-plugin-camera
- cordova-plugin-device 获取设备信息整理
- cordova-plugin-local-notifications本地通知推送在cordova 5.0.0以上版本编译报错解决办法
- Android 拍照和图库功能(适配Android 6.0和7.0系统和华为机型问题)
- cordova camera
- Cordova plugin
- cordova plugin
- ionic cordova 报错
- UIImagePickerController从拍照、图库、相册获取图片
- poj 1948(搜索+剪枝)
- Hibernate 映射多对多关联关系
- Can't load IA 32-bit .dll on a AMD 64-bit platform
- jQuery.inArray判断指定值在数组是否存在
- 字符串加密解密
- 华为机型 cordova-plugin-camera从图库获取报错
- js如何查找数组中是否存在某个值
- Matlab灰色预测和统计分析
- openFileOutput()
- JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2解决
- GDKOI2016总结
- nw.js node-webkit系列(7)Native UI API Menu的使用
- ubuntu vmware bridged mode on surf
- Rendering Path