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);
}