【问题标题】:Error converting file path转换文件路径时出错
【发布时间】:2013-11-29 04:21:38
【问题描述】:

我在将 path UriKITKAT 转换为 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);
}

【问题讨论】:

    标签: android path base64


    【解决方案1】:

    因为KITKAT现在有一些其他的文件处理机制,所以我使用了以下:

    if (Build.VERSION.SDK_INT < 19) {
                        Intent intent = new Intent();
                        intent.setType("image/*");
                        intent.setAction(Intent.ACTION_GET_CONTENT);
                        startActivityForResult(
                                Intent.createChooser(intent, "Choose Picture"),
                                FROM_GALLERY);
                    } else {
                        Intent intent = new Intent(
                                Intent.ACTION_PICK,
                                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(intent, FROM_GALLERY);
                    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-22
      • 1970-01-01
      • 2015-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-11
      相关资源
      最近更新 更多