如何显示onActivityResult

时间:2018-08-22 11:39:08

标签: android android-camera image-gallery

我是android的新手,我已经开发了一个应用程序,用户可以根据上下文菜单选项从相机或图库中选取图像以显示在封面或个人资料页面上。

那么我如何根据用户选择显示图像,无论是封面还是个人资料页面?

我在这里尝试过onActivityResult:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
    switch (requestCode) {
        case 0:
            if (resultCode == RESULT_OK) {
                Uri selectedImage = imageReturnedIntent.getData();
                imageCoverPage.setImageURI(selectedImage);
            } else {
                Uri selectedImage = imageReturnedIntent.getData();
                profileImage.setImageURI(selectedImage);
            }
            break;

        case 1:
            if (resultCode == RESULT_OK) {
                Uri selectedImage = imageReturnedIntent.getData();
                imageCoverPage.setImageURI(selectedImage);
            } else {
                Uri selectedImage = imageReturnedIntent.getData();
                profileImage.setImageURI(selectedImage);
            }
            break;
    }
}

0 个答案:

没有答案