老版本项目在使用picture_library图片选择时会出现下面错误信息 This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry. The following AndroidX dependencies are detected: androidx.appcompat:appcompat:1.0.0, androidx.versionedparcelable:versionedparcelable:1.0.0, androidx.fragment:fragment:1.0.0, androidx.slidingpanelayout:slidingpanelayout:1.0.0, androidx.core:core:1.0.0, androidx.customview:customview:1.0.0, 解决方法:修改 picture_library的版本,在 picture_library:v2.2.5及以下版本不会报上面错误信息 api 'com.github.LuckSiege.PictureSelector:picture_library:v2.2.5'
如果使用 picture_library,就不用导入Glide依赖,picture_library会自动导入Glide依赖包
使用方法
1、调用选择器
PictureSelector.create(this).openGallery(PictureMimeType.ofImage()) .maxSelectNum(1)//最大选择数量 .minSelectNum(0) .videoMaxSecond(0)//视频最大数量 .imageSpanCount(3) .selectionMode(PictureConfig.SINGLE) .previewImage(true) .isCamera(true) .isZoomAnim(true) .enableCrop(false) .compress(true) .hideBottomControls(false) .isGif(false) .freeStyleCropEnabled(true) .minimumCompressSize(100) .forResult(IMG_REQUEST_CODE);
2、处理
public void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data);
Uri[] results = null;
ListfilesMediaData = PictureSelector.obtainMultipleResult(data);
if (resultCode == RESULT_OK) { if (data == null) { results = new Uri[]{imageUri}; } else {
String dataString = data.getDataString(); ClipData clipData = data.getClipData(); if (clipData != null) { results = new Uri[clipData.getItemCount()]; for (int i = 0; i < clipData.getItemCount(); i++) { ClipData.Item item = clipData.getItemAt(i); results[i] = item.getUri(); } } ListfilesMediaData = PictureSelector.obtainMultipleResult(data); if (filesMediaData != null) { results = new Uri[filesMediaData.size()]; for (int i = 0; i < filesMediaData.size(); i++) { LocalMedia item = filesMediaData.get(i); results[i] = Uri.fromFile(new File(item.getCompressPath())); } } if (dataString != null) { results = new Uri[]{Uri.parse(dataString)}; }
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)