0

** Main Activity **

** How can I solve this problem, I want to get crop image to photo editing Activity for further use, please anyone solves this. **

public class MainActivity extends AppCompatActivity {

ImageView more_vert,image;
LinearLayout album,start;
public static Uri uri;
public static  Bitmap bitmap;
int REQUEST_IMAGE_CODE = 10;

private static final String TAG = MainActivity.class.getSimpleName();
public static final int REQUEST_IMAGE = 100;

String[] permission = {Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    binding();
    onclick();



}

private void onclick() {
    start.setOnClickListener(new View.OnClickListener() {
        @RequiresApi(api = Build.VERSION_CODES.M)
        @Override
        public void onClick(View view) {

            if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){

                requestPermissions(permission,REQUEST_IMAGE_CODE);
            }
             else{

                onChooseImage();

            }
        }
    });

    album.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            startActivity(new Intent(MainActivity.this,AlbumActivity.class));
        }
    });

    more_vert.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            PopupMenu menu = new PopupMenu(MainActivity.this, more_vert);
            menu.getMenuInflater().inflate(R.menu.home_menu, menu.getMenu());

            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {

                    switch (menuItem.getItemId()) {

                        case R.id.rate_us:
                            Toast.makeText(MainActivity.this, "Rate US", Toast.LENGTH_SHORT).show();
                            break;

                        case R.id.share:
                            Toast.makeText(MainActivity.this, "Share", Toast.LENGTH_SHORT).show();
                            break;

                        case R.id.more:
                            Toast.makeText(MainActivity.this, "More", Toast.LENGTH_SHORT).show();
                            break;

                        case R.id.privacy_policy:
                            Toast.makeText(MainActivity.this, "Privacy Policy", Toast.LENGTH_SHORT).show();
                            break;
                    }

                    return false;
                }
            });

            menu.show();

        }
    });
}

public void onChooseImage() {
    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*");
    startActivityForResult(intent,REQUEST_IMAGE_CODE);
}

private void binding() {
    more_vert = findViewById(R.id.more_vert);
    album = findViewById(R.id.album);
    start = findViewById(R.id.start);
}


@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);


    if (resultCode == RESULT_OK && requestCode == REQUEST_IMAGE_CODE){

        uri = data.getData();

            Intent intent = new Intent(MainActivity.this,Image_cropActivity.class);

            startActivity(intent);

    }
}

}

** CropActivity **

public class Image_cropActivity extends AppCompatActivity {

ImageView done;
public static CropImageView cropImageView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_crop);

    done = findViewById(R.id.done);
    cropImageView = findViewById(R.id.cropImageView);

    cropImageView.setImageUriAsync(uri);


    done.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            cropImageView.getCroppedImage();

            Intent intent = new Intent(Image_cropActivity.this,PhotoEditingActivity.class);
            startActivity(intent);

        }
    });
}

** Editing Activity**

public class PhotoEditingActivity extends AppCompatActivity {

ImageView imageView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo_editing);

    imageView = findViewById(R.id.imageView);
enter code here

    imageView.setImageURI(uri);
}

}

Vishal Vasani
  • 647
  • 8
  • 16

1 Answers1

1

You need to send the data to the new activity to which you are starting in your case PhotoEditingActivity and also to your Image_cropActivity (here you should be getting the URI from the previous activity which I am not seeing in your code). You need to put data into the intent and retrieve that in your onCreate. SO you case you need to save your crop image in temp and send the URI for that to next activity through intent.

Check this to see how to send data using intent

weblinux
  • 19
  • 2
  • Image Is coming to Image_cropActivity But when I perform a click event only cropped image should pass to PhotoEditingActivity – Shivam Jun 04 '22 at 03:39
  • Try to save the cropped image and pass that image to photoediting activity or pass the crop rect and use that rect to again draw in the photoeditingactivity. You can use transformation to scale the image to the crop handles. – weblinux Jun 05 '22 at 05:54