[英]No Activity found to handle Intent{typ=andrid.intent.action.PICK}
Well, I can't recognize why the problem below show up.好吧,我不明白为什么会出现下面的问题。 I created an
imageView
button that when it is clicked it should open gallery to choose an image.我创建了一个
imageView
按钮,单击它时应该打开图库以选择图像。 Although, it triggers the following problem: No Activity found to handle Intent{typ=andrid.intent.action.PICK}
.虽然,它触发了以下问题:
No Activity found to handle Intent{typ=andrid.intent.action.PICK}
。 Take a look at the code I wrote.看看我写的代码。
private ImageView imgContainer
private Bitmap storedImg;
private static final int PICK_IMAGE_REQUEST = 100;
private Uri imgPath;
postTypes = view.findViewById(R.id.PostOptions);
try {
imgContainer = view.findViewById(R.id.pressToUpload);
} catch (Exception e) {
}
imgContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Intent intent = new Intent();
intent.setType("image/*");
intent.setType(Intent.ACTION_PICK);
startActivityForResult(intent, PICK_IMAGE_REQUEST);
} catch (Exception e) {
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
postTypes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu menu = new PopupMenu(getContext(), postTypes);
menu.getMenuInflater()
.inflate(R.menu.post_options, menu.getMenu());
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.txtOption:
imgPreview.setVisibility(View.GONE);
return true;
case R.id.imgOption:
imgPreview.setVisibility(View.VISIBLE);
return true;
case R.id.vdOption:
imgPreview.setVisibility(View.GONE);
break;
}
return true;
}
});
menu.show();
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
try {
ContentResolver resolver = getActivity().getContentResolver();
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data!=null && data.getData()!=null) {
imgPath = data.getData();
storedImg = MediaStore.Images.Media.getBitmap(resolver, imgPath);
imgContainer.setImageBitmap(storedImg);
}
} catch (Exception e) {
}
}
Is it a problem with ACTION_PICK
? ACTION_PICK
有问题吗? Before ACTION_PICK
I tried ACTION_GET_CONTENT
but the same issue was triggered.在
ACTION_PICK
之前,我尝试ACTION_GET_CONTENT
但触发了相同的问题。 What does it need in order to open the gallery?打开画廊需要什么?
Could you try this, ACTION_PICK
fails sometimes when the phone doesn't properly support it.你能试试这个吗,
ACTION_PICK
有时会在手机不能正确支持它时失败。
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.