官方給的 imagePicker插件不僅功能少 而且 問題多秧饮,所以師兄就在github找到了一個依然在維護的插件
圖片選擇器巧还,但是師兄安裝使用之后發(fā)現(xiàn)BUG也很多。瓮孙。唐断。
于是我花了一下午時間选脊,看源碼、修BUG(表示很痛苦脸甘。恳啥。。)
但是功夫不負有心人丹诀,師兄成功了6鄣摹!铆遭!
下面給小伙伴們介紹一下這個imagePickerPlus的問題及解決辦法
1.點擊圖片返回后圖片沒有了硝桩。。枚荣。
在觸發(fā) ImagePicker.getPictures方法后碗脊,成功的加載出來圖片了(和微信很像有木有~),但是很快問題來了橄妆,隨意點擊一張圖片后衙伶,再返回,圖片就沒有了害碾,這尼瑪矢劲。。慌随。如圖
后來經(jīng)過師兄的不懈努力(AS)終于找到原因了卧须。。儒陨。
ImageDataSource.java 中的loaderManager用完沒有銷毀啊花嘶,重復(fù)加載了有木有啊1哪M衷薄!這笛园。隘击。。
解決辦法:
在ImageDataSource.java ?做如下修改:
```(一)聲明一個全局私有的LoaderManager?
private LoaderManager loaderManager=null;
(二)ImageDataSource方法中修改:
loaderManager = activity.getSupportLoaderManager();
(三)onLoadFinished方法最后添加
if(loaderManager.getLoader(LOADER_ALL)!=null){
loaderManager.destroyLoader(LOADER_ALL);
}```
2.返回鍵不好使研铆,一按就GG
這就是疏忽埋同!
解決辦法:
在ImageGridActivity.java中添加,并且要引入?import android.view.KeyEvent;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() ==0) {
// 按下BACK棵红,同時沒有重復(fù)
? ? //Log.d(WZLOG, "onKeyDown()");
? }
return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
//Log.d(WZLOG, "onBackPressed()");
? super.onBackPressed();
}
3.各種類似于"Failed resolution of: Landroid/support/v4/view/KeyEventCompat"的BUG
這個就是V4凶赁、V7的問題
解決辦法:
修改build.gradle配置文件
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group =='com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion'25.3.0'
? ? }
}
}
}
dependencies {
compile fileTree(dir:'libs',include:'*.jar')
// SUB-PROJECT DEPENDENCIES START
? ? debugCompile(project(path:"CordovaLib",configuration:"debug"))
releaseCompile(project(path:"CordovaLib",configuration:"release"))
compile"com.android.support:support-v4:27.0.0+"
? ? compile"com.android.support:appcompat-v7:27.0.1"
? ? compile"com.github.chrisbanes.photoview:library:1.2.4"
? ? compile"com.android.support:recyclerview-v7:25.1.1"
? ? compile"com.squareup.picasso:picasso:2.5.2"
? ? compile"com.nostra13.universalimageloader:universal-image-loader:1.9.5"
? ? compile"org.xutils:xutils:3.3.36"
? ? compile"com.github.bumptech.glide:glide:3.7.0"
? ? // SUB-PROJECT DEPENDENCIES END
}
4.文件路徑權(quán)限問題,插件不能獲取圖片
插件內(nèi)部把選擇的圖片進行壓縮后,放置到了cache中虱肄,部分手機不能獲取
解決辦法:
修改CompressHelper.java
private CompressHelper(Context context) {
this.context = context;
// destinationDirectoryPath = context.getCacheDir().getPath() + File.pathSeparator + FileUtil.FILES_PATH;
//destinationDirectoryPath = context.getCacheDir().getPath()? + FileUtil.FILES_PATH;
? ? destinationDirectoryPath = context.getExternalCacheDir().getPath()? + FileUtil.FILES_PATH;
}
完美解決