我一直在遵循有关如何选择图片,裁剪并上传到我的应用程序的教程...它选择了,它裁剪了,但是上传了未裁剪的图片...我看不到任何错误。 ..
有:
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == REQUEST_WRITE_PERMISSION && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//THIS IS HAPPEN WHEN USER CLICK ALLOW ON PERMISSION
//START PICK IMAGE ACTIVITY
CropImage.startPickImageActivity(addceleb.this);
}
}
这将启动功能:
@Override
@SuppressLint("NewApi")
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri imageUri = CropImage.getPickImageResultUri(this, data);
Log.i("RESPONSE getPath", imageUri.getPath());
Log.i("RESPONSE getScheme", imageUri.getScheme());
Log.i("RESPONSE PathSegments", imageUri.getPathSegments().toString());
//GET IMAGEVIEW RESULT URI AND PASS TO IMAGEVIEW
imageView.setImageURI(imageUri);
//NOW CROP IMAGE URI
CropImage.activity(imageUri)
.setGuidelines(CropImageView.Guidelines.ON)
.setMultiTouchEnabled(true)
.setRequestedSize(800, 800)
.setAspectRatio(1,1)
.start(this);
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
Log.i("RESPONSE getUri", result.getUri().toString());
//GET CROPPED IMAGE URI AND PASS TO IMAGEVIEW
imageView.setImageURI(result.getUri());
}
}
}
显示以下建议:
Condition 'requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE' is always 'false' less... (Ctrl+F1)
Inspection info: This inspection analyzes method control and data flow to report possible conditions that are always true or false, expressions whose value is statically proven to be constant, and situations that can lead to nullability contract violations.
Variables, method parameters and return values marked as @Nullable or @NotNull are treated as nullable (or not-null, respectively) and used during the analysis to check nullability contracts, e.g. report NullPointerException (NPE) errors that might be produced.
More complex contracts can be defined using @Contract annotation, for example:
@Contract("_, null -> null") — method returns null if its second argument is null @Contract("_, null -> null; _, !null -> !null") — method returns null if its second argument is null and not-null otherwise @Contract("true -> fail") — a typical assertFalse method which throws an exception if true is passed to it
The inspection can be configured to use custom @Nullable
@NotNull annotations (by default the ones from annotations.jar will be used)
答案 0 :(得分:1)
这是有条件的:
if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE /* && ... */) {
// ...
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
// ...
}
}
除非PICK_IMAGE_CHOOSER_REQUEST_CODE == CROP_IMAGE_ACTIVITY_REQUEST_CODE
,否则您以后的情况将为假。