gpt4 book ai didi

java - 无法选择要在 ImageView 中显示的图像

转载 作者:行者123 更新时间:2023-12-02 03:01:44 25 4
gpt4 key购买 nike

我正在尝试将手机中的图像显示到 ImageView 中,以上传到 Firebase 存储。但是,我无法从手机中选择要上传的文件。

我目前正在学习本教程:https://www.youtube.com/watch?v=QNcd41C-IEE在 11:00 分钟标记处,我还需要添加更多代码。

Activity 截图: Activity Screenshot displaying issue

代码:

public class ChallengeUploadAdd extends AppCompatActivity {

private static final int CHOOSE_IMAGE=1;

private Button chooseImage, btnUploadImage;
private TextView viewGallery;
private ImageView imgPreview;
private TextView view_Gallery;
private EditText imgDescription;
private Uri imgUrl;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_challenge_upload_add);
chooseImage=findViewById(R.id.chooseImage);
btnUploadImage=findViewById(R.id.btnUploadImage);


view_Gallery=findViewById(R.id.viewGallery);

imgDescription=findViewById(R.id.imgDescription);
imgPreview=findViewById(R.id.imgPreview);

chooseImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showFileChoose();
}
});
}

private void showFileChoose(){

Intent intent = new Intent();
intent.setType("images/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, CHOOSE_IMAGE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==CHOOSE_IMAGE && resultCode==RESULT_OK && data
!= null && data.getData() !=null){
imgUrl=data.getData();

Picasso.get().load(imgUrl).into(imgPreview);
}
}

}

任何有关我无法从手机中选择图像的原因的帮助将不胜感激。

最佳答案

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("图片/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);

其中 SELECT_PHOTO 为 1

关于java - 无法选择要在 ImageView 中显示的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54431281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com