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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

android通過(guò)Uri.getPath()獲取真實(shí)路徑

android通過(guò)Uri.getPath()獲取真實(shí)路徑

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

3 回答

?
UYOU

TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個(gè)贊

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

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

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊

這就是我做的:

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()方法已棄用,因此我不使用它。

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


查看完整回答
反對(duì) 回復(fù) 2019-08-06
  • 3 回答
  • 0 關(guān)注
  • 25853 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號(hào)

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