我是Android开发的新手,请您解释一下以下代码以及它使用的Android代码是什么?
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
if (requestCode == RESULT_LOAD_IMG && resultCode == getActivity().RESULT_OK
&& null != data) {
selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
// Get the cursor
Cursor cursor = getActivity().getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgPath = cursor.getString(columnIndex);
cursor.close();
String fileNameSegments[] = imgPath.split("/");
fileName = fileNameSegments[fileNameSegments.length - 1];
_txt_img_url.setText(fileName);
Toast.makeText(getActivity(), fileName, Toast.LENGTH_SHORT).show();
ImageTask imgtask = new ImageTask();
imgtask.execute();
答案 0 :(得分:0)
onActivityResult方法用于处理从intent返回的数据, 在这里查看文档 https://developer.android.com/training/basics/intents/result.html
总之,在这种情况下,如果结果没问题,并且我们有数据要处理,则会显示所选文件路径的Toast。