如何解决来自画廊的多选图像在 android 中的某些手机中不起作用
我正在使用 EXTRA_ALLOW_MULTIPLE 请求从图库中选择多张图片。 当我在 One plus 中运行相同的应用程序时,它运行良好并且能够选择多个图像。 无法从三星 M20 的图库中选择多张图像。 我做了很多研究,但无法找到它。 (但可以通过两部手机从“照片”中多选图像)
public class MainActivity extends AppCompatActivity {
public static final int broWSE_RESULT = 1;
ImageAdapter imageAdapter;
ArrayList<Uri> imagesUri = new ArrayList<>();
GridView gridView;
@Override
protected void onCreate(Bundle savedInstanceState) {
Button btn_browse,btn_delete;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView= findViewById(R.id.grid_view);
btn_browse = findViewById(R.id.btn_browse);
btn_browse.setonClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
f_openImageExplorer();
}
});
}
public void f_openImageExplorer() {
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);
intent.setAction(Intent.ACTION_GET_CONTENT);
// startActivityForResult(intent,broWSE_RESULT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"),broWSE_RESULT);
}
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data) {
super.onActivityResult(requestCode,resultCode,data);
if (requestCode == broWSE_RESULT) {
if (resultCode == MainActivity.RESULT_OK) {
if (data.getClipData() != null) {
Toast.makeText(this,Integer.toString(resultCode),Toast.LENGTH_SHORT).show();
int imageCount = data.getClipData().getItemCount();
for(int i = 0; i< imageCount;i++){
Uri imageUri = data.getClipData().getItemAt(i).getUri();
imagesUri.add(imageUri);
imageAdapter= new ImageAdapter(getBaseContext(),imagesUri);
gridView.setAdapter(imageAdapter);
imageAdapter.notifyDataSetChanged();
}
}
else
{
Uri singleImageUri = data.getData();
imagesUri.add(singleImageUri);
ImageAdapter imageAdapter= new ImageAdapter(getBaseContext(),imagesUri);
gridView.setAdapter(imageAdapter);
imageAdapter.notifyDataSetChanged();
}
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。