7
我浏览过图库中的图像并将其设置为ImageView
现在我需要获取已在ImageView
中设置的图像图像名称。下面附上了我的代码。获取图片在android中选择的图像名称
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("req","req"+requestCode);
Log.d("res","res"+resultCode);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
imageView = (ImageView) findViewById(R.id.imgView);
imageView1 = (ImageView) findViewById(R.id.imgView1);
if(browse == 1){
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
if(browse == 2){
imageView1.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
String resName = getResources().getResourceEntryName(R.id.imgView);
Toast.makeText(getApplicationContext(), "BBB"+resName,Toast.LENGTH_LONG).show();
}
感谢ü获取文件名...如何比较两个file..but图片路径是相同 – user3415586
使用此功能f.compareTo(文件2); – Shini
camp f f1.compareTo(f2);我得到价值0 – user3415586