相冊(cè)選擇以后根據(jù)uri獲取圖片路徑

Intent intent =new Intent(Intent.ACTION_PICK, null);

intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,"image/*");

if (getActivity()==null)

return;

startActivityForResult(intent, TakePhotoEnum.CHOICE_ALBUM.getRequestCode());



case 202:

if(resultCode==RESULT_OK){

mListImage.remove(mListImage.size()-1);

? ? ? ? Uri uri = data.getData();

? ? ? ? mListImage.add(new PostImageBean(getDataColumn(uri,null,null)));

? ? ? ? mListImage.add(new PostImageBean(""));

? ? ? ? mBaseRecyclerAdapter.init(mListImage);

? ? ? ? mBaseRecyclerAdapter.notifyDataSetChanged();

? ? }

break;




/**

* 根據(jù)uri獲取當(dāng)前路徑

*/

public StringgetDataColumn(Uri uri, String selection, String[] selectionArgs) {

Cursor cursor =null;

? ? final String column ="_data";//路徑保存在downloads表中的_data字段

? ? final String[] projection = {column};

? ? try {

cursor = getContext().getContentResolver().query(uri, projection, selection, selectionArgs, null);

? ? ? ? if (cursor !=null && cursor.moveToFirst()) {

final int column_index = cursor.getColumnIndexOrThrow(column);

? ? ? ? ? ? return cursor.getString(column_index);

? ? ? ? }

}catch (Exception e) {

e.printStackTrace();

? ? }finally {

if (cursor !=null)

cursor.close();

? ? }

return null;

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 原文章地址:Android 4.4從圖庫(kù)選擇圖片,獲取圖片路徑并裁剪 最近在做一個(gè)從圖庫(kù)選擇圖片或拍照,然后裁剪的...
    如若成楓閱讀 1,275評(píng)論 0 3
  • 只簡(jiǎn)述我發(fā)現(xiàn)問題的根源,有些是適配了7.0,會(huì)報(bào)權(quán)限失敗問題,那是由于沒有動(dòng)態(tài)授權(quán)導(dǎo)致,接下來(lái)我一步一步給大家實(shí)現(xiàn)...
    Wocus閱讀 2,456評(píng)論 4 5
  • http://blog.csdn.net/earbao/article/details/50716747 http...
    王培921223閱讀 985評(píng)論 0 0
  • Android 一鍵分享時(shí)分享的圖片 // imagePath是圖片的本地路徑,Linked-In以外的平臺(tái)都支持...
    自然之秋閱讀 419評(píng)論 0 0
  • 小腳丫 真淘氣 手拿彩筆墻上畫 畫個(gè)太陽(yáng)紅彤彤 畫朵花兒笑哈哈 小腳丫 志向大 懷揣夢(mèng)想成學(xué)霸 讀書習(xí)字學(xué)畫畫 跑...
    艾彌兒閱讀 659評(píng)論 2 20

友情鏈接更多精彩內(nèi)容