如何从android中的galary获取图像的名称 [英] how to get the name of an image from galary in android
本文介绍了如何从android中的galary获取图像的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一段代码可以从库中获取所选图像的路径。现在我想得到图像的名称而不是路径。我怎么能这样做,
我用来获取路径的代码是
i have a piece of code that gets the path of the selected image from the gallery. now i want to get just the name of the image instead of the path. how can i do it,
the code that i used for getting the path is
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == PICK_IMAGE)
{
Uri imageUri = data.getData();
imageView.setImageURI(imageUri);
}
if (resultCode == RESULT_OK) {
Uri selectedImageUri = data.getData();
File f = new File("" + selectedImageUri);
String s = getRealPathFromURI(selectedImageUri);
f.getName();
TextView tv= (TextView) findViewById(R.id.textView);
tv.setText(s);
}
}
public String getRealPathFromURI(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
@SuppressWarnings("deprecation")
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
推荐答案
尝试 http://developer.android.com/reference/android/net/Uri.html#getPathSegments() [ ^ ]。
这篇关于如何从android中的galary获取图像的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文