0
我遇到問題,特別是將路徑Uri從KITKAT
轉換爲Base64格式。該代碼適用於API 18及更低版本的所有設備。有人可以請幫助。轉換文件路徑時出錯
11-29 09:57:44.407: I/FILE_URI(23833): content://com.android.providers.media.documents/document/image%3A6108
這是從路徑烏里返回的內容。
以下爲Base64編碼的轉換代碼:
public void getGalleryDetails(String path) throws FileNotFoundException {
InputStream inputStream = new FileInputStream(path);
byte[] bytes;
byte[] buffer = new byte[8192];
int bytesRead;
ByteArrayOutputStream output = new ByteArrayOutputStream();
try{
while((bytesRead = inputStream.read(buffer)) != -1){
output.write(buffer, 0, bytesRead);
}
}catch(IOException e){
e.printStackTrace();
}
bytes = output.toByteArray();
encodedImage = Base64.encodeToString(bytes, Base64.DEFAULT);
Log.i("ENCODED", encodedImage);
}