3 回答

TA貢獻(xiàn)2065條經(jīng)驗(yàn) 獲得超14個(gè)贊
將content:// URI轉(zhuǎn)換為Android 4.4中的實(shí)際路徑
在任何Android版本上都沒有可靠的方法來執(zhí)行此操作。A content:// Uri不必代表文件系統(tǒng)上的文件,更不用說您可以訪問的文件了。
Android 4.4提供存儲(chǔ)框架的更改只是增加了您遇到content:// Uri值的頻率。
如果得到a content:// Uri,請(qǐng)使用ContentResolver和方法(例如openInputStream()和)使用它openOutputStream()。

TA貢獻(xiàn)2011條經(jīng)驗(yàn) 獲得超2個(gè)贊
我也一直面臨這個(gè)問題,但就我而言,我想做的就是為Gallery指定一個(gè)具體的Uri,以便以后可以使用裁剪??雌饋碓谛碌腒itKat文檔瀏覽器中,除非您在導(dǎo)航抽屜中選擇galery,然后像您說的那樣直接從那里打開圖像或文件,否則我們將無法再這樣做。
在Uri情況下,從文檔瀏覽器打開時(shí),您仍然可以檢索路徑。
Intent dataIntent= new Intent(Intent.ACTION_GET_CONTENT);
dataIntent.setType("image/*"); //Or whatever type you need
然后在onActivityResult中:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ACTIVITY_SELECT_IMAGE && resultCode == RESULT_OK) {
myUri = data.getData();
String path = myUri.getPath();
openPath(myUri);
}
}
如果您需要然后使用該路徑打開文件,則只需使用Content Resolver:
public void openPath(Uri uri){
InputStream is = null;
try {
is = getContentResolver().openInputStream(uri);
//Convert your stream to data here
is.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
- 3 回答
- 0 關(guān)注
- 528 瀏覽
添加回答
舉報(bào)