安卓上传图片上传图片

2023-09-05 23:06:11 作者:小仙女

我的图像选择和上传的部分问题。 首先,这里的错误信息

  2月8号至4日:14:21.912:DEBUG / PHOTOUPLOADER(576):java.io.FileNotFoundException:/内容:/媒体/外部/图片/媒体/ 1(没有这样的文件或目录)
2月8日至4日:14:32.124:WARN / System.err的(576):java.io.FileNotFoundException:/内容:/媒体/外部/图片/媒体/ 1(没有这样的文件或目录)
 

在活动中,我选择多媒体资料中的图像,并尝试使用URI路径(如日志中,我的测试图像的URI路径是/内容:/媒体/外部/图片/媒体/ 1)上传这张照片至Facebook。而我得到了上面的错误消息。我只是想知道,如果这是一个文件路径的正确格式?或者我应该使之成为像SD卡\ image.png?

解决方案

 公共字符串getPath(URI URI){
    的String []投影= {MediaStore.Images.Media.DATA};
    光标光标= managedQuery(URI,投影,NULL,NULL,NULL);
    startManagingCursor(光标);
    INT与Column_Index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    返回cursor.getString(Column_Index中);
}
 

我用金山手机助手上传图片到安卓手机,可总是提示上传文件或目录到手机失败是怎么回事

I got a question in the part of image selecting and uploading. first, here's error message

08-04 02:14:21.912: DEBUG/PHOTOUPLOADER(576): java.io.FileNotFoundException: /content:/media/external/images/media/1 (No such file or directory)
08-04 02:14:32.124: WARN/System.err(576): java.io.FileNotFoundException: /content:/media/external/images/media/1 (No such file or directory)

In the activity, I choose a image from Gallery and trying to use the uri path (as in the log, the uri path for my test image is /content:/media/external/images/media/1 )to upload this photo to facebook. and I got the above error message. I'm just wondering if this is the correct format of a file path? or should I make it to be something like sdcard...\image.png ?

解决方案

public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    startManagingCursor(cursor);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}