【发布时间】:2016-06-30 11:56:01
【问题描述】:
这是我的代码。我想从相机或图库中选择图像。 为此,我必须检查设备的相机支持功能。
public void selectImage() {
final String[] items = new String[]{"Camera", "Gallery"};
final Integer[] icons = new Integer[]{R.drawable.ic_camera, R.drawable.ic_gallery};
ListAdapter adapter = new ArrayAdapterWithIcon(getActivity(), items, icons);
new AlertDialog.Builder(getActivity()).setTitle("Select Picture")
.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Camera")) {
if (//here i want to check is there mobile exists camera or not) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);
}
} else if (items[item].equals("Gallery")) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
}
}
}).show();
}
我尝试了很多,但没有成功。
【问题讨论】:
标签: android