Initially I used standard tools, but the problem was discovered during testing (described here - https://commonsware.com/blog/2013/01/23/no-android-does-not-have-crop-intent.html ). Therefore, I decided to use the following library for Crop - https://github.com/jdamcd/android-crop . Once figured out, run and get the error
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=6709, result=-1, data=Intent { (has extras) }} to activity {ru.fuse8.socrat/ru.fuse8.socrat.activity.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageURI(android.net.Uri)' on a null object reference Source:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent result) { if (requestCode == Crop.REQUEST_PICK && resultCode == RESULT_OK) { beginCrop(result.getData()); } else if (requestCode == Crop.REQUEST_CROP) { handleCrop(resultCode, result); } } private void beginCrop(Uri source) { Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped")); Crop.of(source, destination).asSquare().start(this); } private void handleCrop(int resultCode, Intent result) { if (resultCode == RESULT_OK) { mAvatarImageView.setImageURI(Crop.getOutput(result)); } else if (resultCode == Crop.RESULT_ERROR) { Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show(); } } The error crashes on the line:
mAvatarImageView.setImageURI(Crop.getOutput(result)); PS before that I tried 3-4 libraries and all had the same problem: in Intent, when it comes in for the second time onActivityResult, as if there is no data with an edited image.
PSS Ad mAvatarImage (it is in the fragment, and the code above is in activity)
mAvatarImageView = (ImageView) view.findViewById(R.id.profile_avatar_image_view); mAvatarImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setAction(Intent.ACTION_GET_CONTENT); photoPickerIntent.setType("image/*"); getActivity().startActivityForResult(photoPickerIntent, 9162); } });
nullbefore calling thesetImageURImethod - ermak0ff