我想创建一个Android电子商务应用程序,允许用户上传多个图像并将其保存在firebase中。但我似乎找不到任何有用的教程如何做到这一点。请帮助您提供示例代码。
这是我在onActivityResult中的代码:
switch (requestCode) {
case 0:
if (resultCode == RESULT_OK) {
mImageUri = data.getData();
activity(mImageUri)
.setGuidelines(CropImageView.Guidelines.ON)
.start(this);
mSelectImage.setImageURI(mImageUri);
}
break;
case 1:
if(resultCode == RESULT_OK){
mImageUri = data.getData();
activity(mImageUri)
.setGuidelines(CropImageView.Guidelines.ON)
.start(this);
mSelectImage.setImageURI(mImageUri);
}
break;
}
if (requestCode == CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
ActivityResult result = getActivityResult(data);
if (resultCode == RESULT_OK) {
mImageUri = result.getUri();
mSelectImage.setImageURI(mImageUri);
} else if (resultCode == CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Exception error = result.getError();
}
}
}
private void selectImage() {
final CharSequence[] items = {"Take Photo", "Choose from Library",
"Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(
PostActivity.this);
builder.setTitle("Add Photo");
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Take Photo")) {
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePicture.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePicture, 0);}
} else if (items[item].equals("Choose from Library")) {
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto , 1);
} else if (items[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}`
图库请求工作正常,但拍照后相机请求崩溃了。我可以添加或删除什么?
请注意我正在使用theartofdev cropping