由网友(别回头了)分享简介:在使用Intent.ACTION_GET_CONTENT启动照片选择器检索所选项目的URI 检索URI路径,这样我可以张贴到我的网络服务器Launch photo picker using Intent.ACTION_GET_CONTENTRetrieve URI of selected itemRetrieve...在使用Intent.ACTION_GET_CONTENT启动照片选择器
检索所选项目的URI
检索URI路径,这样我可以张贴到我的网络服务器 Launch photo picker using Intent.ACTION_GET_CONTENT Retrieve URI of selected item
Retrieve PATH of URI so that I can POST it to my webserver
code,推出浏览
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, BROWSE_IMAGE_REQUEST_CODE);
code检索选定的图片
if (RESULT_OK == resultCode &&
BROWSE_IMAGE_REQUEST_CODE == requestCode) {
Uri uri = data.getData();
code发送到Web服务器
File file = new File(uri.getPath());
new FileSystemResourceFile(file);
我目前能检索的URI的路径没有概率 /外部/图片/媒体/ 24
但出于某种奇怪的原因,文件总是空,帮助吗?
I am currently able to retrieve the PATH from the URI no prob /external/images/media/24
but for some weird reason file is always null, help please?
推荐答案
我做这个方法转换乌里
从 Intent.ACTION_GET_CONTENT
来真正的路径:
I've done this method to convert Uri
from Intent.ACTION_GET_CONTENT
to real path:
public static String getRealPathFromUri(Activity activity, Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
而这又转化成文件
:
Uri filePathFromActivity = (Uri) extras.get(Intent.EXTRA_STREAM);
filePathFromActivity = Uri.parse(FileUtil.getRealPathFromUri( (Activity) IntentActivity.this, filePathFromActivity));
File imageFile = new File(filePathFromActivity.getPath());
相关推荐
最新文章