第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

android通過Uri.getPath()獲取真實路徑

android通過Uri.getPath()獲取真實路徑

android通過Uri.getPath()獲取真實路徑我正試圖從畫廊獲取圖像。Intent intent = new Intent();intent.setType("image/*");intent.setAction(Intent.ACTION_GET_CONTENT);startActivityForResult(Intent.createChooser(intent, "Select picture"), resultCode );從這個活動返回后,我有一個包含Uri的數(shù)據(jù)??雌饋硐瘢篶ontent://media/external/images/1如何將此路徑轉(zhuǎn)換為真實路徑(就像' /sdcard/image.png')?謝謝
查看完整描述

3 回答

?
UYOU

TA貢獻1878條經(jīng)驗 獲得超4個贊

你真的有必要獲得物理路徑嗎?
例如,ImageView.setImageURI()并且ContentResolver.openInputStream()允許你訪問一個文件的內(nèi)容,不知道它的真實路徑。

查看完整回答
反對 回復(fù) 2019-08-06
?
慕哥9229398

TA貢獻1877條經(jīng)驗 獲得超6個贊

這就是我做的:

Uri selectedImageURI = data.getData();imageFile = new File(getRealPathFromURI(selectedImageURI));

和:

private String getRealPathFromURI(Uri contentURI) {
    String result;
    Cursor cursor = getContentResolver().query(contentURI, null, null, null, null);
    if (cursor == null) { // Source is Dropbox or other similar local file path
        result = contentURI.getPath();
    } else { 
        cursor.moveToFirst(); 
        int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); 
        result = cursor.getString(idx);
        cursor.close();
    }
    return result;}

注意:managedQuery()方法已棄用,因此我不使用它。

最后編輯:改進。我們應(yīng)該關(guān)閉光標(biāo)!!


查看完整回答
反對 回復(fù) 2019-08-06
  • 3 回答
  • 0 關(guān)注
  • 25877 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號