【发布时间】:2013-11-29 04:21:38
【问题描述】:
我在将 path Uri 从 KITKAT 转换为 Base64 格式时遇到问题。该代码适用于所有使用 API 18 及更低版本的设备。有人可以帮忙吗。
11-29 09:57:44.407: I/FILE_URI(23833): content://com.android.providers.media.documents/document/image%3A6108
这是从路径Uri返回的内容。
以下是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);
}
【问题讨论】: