I pass the image url to the following method
private void performCrop(Uri imageUri){ try { Intent intent = new Intent("com.android.camera.action.CROP"); // intent.setType("image/*"); intent.setDataAndType(imageUri, "image/*"); List<ResolveInfo> list = getActivity().getPackageManager().queryIntentActivities( intent, 0 ); int size = list.size(); if (size >= 0) { intent.setData(imageUri); intent.putExtra("crop", "true"); intent.putExtra("aspectX", 0); intent.putExtra("aspectY", 0); intent.putExtra("outputX", 150); intent.putExtra("outputY", 150); intent.putExtra("scale", true); intent.putExtra("scaleUpIfNeeded", true); intent.putExtra("return-data", true); Intent i = new Intent(intent); ResolveInfo res = list.get(0); i.setComponent( new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); System.out.println("before startActivityForResult"); try{ startActivityForResult(i, 2); }catch(Exception e){ e.printStackTrace(); } } } catch(ActivityNotFoundException anfe){ String errorMessage = "Whoops - your device doesn't support the crop action!"; //Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT); //toast.show(); } }
some images are cropped, but some images are missing. When I crop the image, my application activity is closed and the application starts its previous or start activity, what is the problem?
The main problem is that I do not receive any warnings or errors in the log cat, and when I debug it to "System.out.println (" before startActivityForResult "); the program excutes, this means that it does not enter or calls onActivityResult ().
the onActivityResult method is used here.
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(requestCode ==2 && resultCode == getActivity().RESULT_OK){ System.out.println("inside logic..."); try{ if (data != null) { // get the returned data Bundle extras = data.getExtras(); // get the cropped bitmap Bitmap bmp = extras.getParcelable("data"); imageView.setImageBitmap(bmp); } }catch(Exception e){ e.printStackTrace(); } } }