NullPointerException Error while using AsyncTask in onActivityResult - android

I want to Select Image from gallery and crop it,then upload the image to server.If upload success,change view,if upload fail,them give a message;
I Use onActivityResult to manage this,and I use AsyncTask to make http post, dismiss the progressDialog,and save Image,Then i ran to this error
java.lang.RuntimeException: Failure delivering result ResultInfo...
and it caused by
Caused by: java.lang.NullPointerException
in my AsyncTask codes;
Here is my button to crop
avatarButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent,1);
}
});
and onActivityResult code
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode){
case 1:
if (data != null) {
Uri uri = data.getData();
crop(uri);
}
case 2:
if (data != null) {
final Bitmap bitmap = data.getParcelableExtra("data");
new UploadAvatar(UserProfileActivity.this, bitmap).execute();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
Crop method
private void crop(Uri uri) {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 100);
intent.putExtra("outputY", 100);
intent.putExtra("outputFormat", "PNG");
intent.putExtra("noFaceDetection", true);
intent.putExtra("return-data", true);
startActivityForResult(intent, 2);
}
and AsyncTask class
class UploadAvatar extends AsyncTask<Void,Integer,Boolean> {
private Context context;
private String avatarString;
private ProgressDialog progressDialog;
private ImageView avatarImage;
private Bitmap avatar;
public UploadAvatar(Context contextin,Bitmap bitmap){
this.context = contextin;
this.avatar = bitmap;
View rootView = ((Activity)contextin).getWindow().getDecorView().findViewById(android.R.id.content);
this.avatarImage = (ImageView)rootView.findViewById(R.id.setavatar);
}
#Override
protected void onPreExecute(){
progressDialog = new ProgressDialog(context);
progressDialog.setMessage("正在上传头像");
progressDialog.setCancelable(true);
progressDialog.show();
ByteArrayOutputStream baos=new ByteArrayOutputStream();
if(avatar == null){
Log.d("222","Null");
}
//Here i Got error,that avatar is null;
avatar.compress(Bitmap.CompressFormat.PNG,90,baos);
byte[] b=baos.toByteArray();
avatarString= new String(b);
}
#Override
protected Boolean doInBackground(Void... param){
//try upload Image to server
}
#Override
protected void onPostExecute(Boolean result){
...//do some work
}
}
It totally confused me,because i got this Error when i click on a Image in gallery,trying to call Crop(),I didn't finish my crop,so the Bitmap data is obvious Null,it seems execute AsyncTask before i finish my crop.It's quite confusing,in the crop() method i start intent to crop like this:startActivityForResult(intent, 2);
But onActivityResult executed the codes before the Result is deliver back.
Please help, Thanks in advance.This really draw me crazy. :(
Update:
Here is some more NullPointerObject stack trace code:
at com.example.allen.bubbles001.Activity.UploadAvatar.onPreExecute(UserProfileActivity.java:229)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
at android.os.AsyncTask.execute(AsyncTask.java:535)
at com.example.allen.bubbles001.Activity.UserProfileActivity.onActivityResult(UserProfileActivity.java:168)
at android.app.Activity.dispatchActivityResult(Activity.java:5423)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3347)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3394)
The first entry point at
avatar.compress(Bitmap.CompressFormat.PNG,90,baos);
in UploadAvatar.onPreExcute
The fourth entry point at
new UploadAvatar(UserProfileActivity.this, bitmap).execute();
in onActivityResult

It's probably the bitmap that is null. You seem to be pulling it out of the "data" Intent, which is probably not a good idea in the first place. Intents have a maximum size limit for extras, and if the Bitmap is large, you will easily go over the limit. Instead, I would recommend saving it to disk and putting the filename in the Intent as an extra so you can read it from the file instead.

Related

startActivityForResults not working when the child activity calls another activity

I have 3 activities say A, B and C.
A calls B.
When B doesn't call C it returns to A. But when B calls C it doesn't return to A, the app stops.
Now the real problem is, from activity A I want to call an image picker and crop the image. That's Activity B which crops and calls C for picking image.
Activity A:
iv_profile_pic.setOnClickListener(new View.OnClickListener() {//iv_profile_pic is an ImageView
#Override
public void onClick(View view) {
Intent i=new Intent(MainActivity.this,profile_pic_chooser.class);
i.setFlags(0);
MainActivity.this.startActivityForResult(i, 999);
Toast.makeText(getApplicationContext(),"Reached",Toast.LENGTH_SHORT).show();
}
});
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == 999) {
Bitmap image=data.getParcelableExtra("picture");
iv_profile_pic.setImageBitmap(image);
}
}
Activity B:
It has 2 buttons. Load and Crop. Load when clicked calls ImageChooserIntent and chooses an image which is opened in B with guidlines to crop.
Crop when clicked should return back to A the cropped image.
If crop is called without calling load, it returns to A with null, of-course.
But if Load is clicked first and then Crop is called, the app simply stops.
public void onLoadImageClick(View view) {
startActivityForResult(getPickImageChooserIntent(), 200);
}
public void onCropImageClick(View view) {
Bitmap cropped = mCropImageView.getCroppedImage(500, 500);
if (cropped != null) {
mCropImageView.setImageBitmap(cropped);
iv.setImageBitmap(cropped);
Intent returnIntent = new Intent();
returnIntent.putExtra("picture", cropped);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
Uri imageUri = getPickImageResultUri(data);
// For API >= 23 we need to check specifically that we have permissions to read external storage,
// but we don't know if we need to for the URI so the simplest is to try open the stream and see if we get error.
boolean requirePermissions = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED &&
isUriRequiresPermissions(imageUri)) {
// request permissions and handle the result in onRequestPermissionsResult()
requirePermissions = true;
mCropImageUri = imageUri;
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
}
if (!requirePermissions) {
mCropImageView.setImageUriAsync(imageUri);
}
}
}
I got a workaround. The most probable problem I was facing was:
I was using an external library for cropping the image. This library did 2 things.
First, selected an image using imageChooser intent.
Second, Cropped that image.
After the library cropped the image, it wasn't saving the cropped image in local/external storage. But I was trying to pass it back to parent directory.
There's the problem. The file doesn't exist and still I am trying to use it. The application terminates.
So my workaround was,
• Save the bitmap in storage
• Pass the Uri to parent
• Extract that Uri from child
• Make bitmap from that Uri
• Apply on the ImageView
So Activity B had:
public void onCropImageClick(View view) {
Bitmap cropped = mCropImageView.getCroppedImage(500, 500);
if (cropped != null) {
mCropImageView.setImageBitmap(cropped);
iv.setImageBitmap(cropped);
File externalStorageDirectory = Environment.getExternalStorageDirectory();
externalStorageDirectory= new File(externalStorageDirectory , "FOLDERNAME");
if(!createDirIfNotExists(externalStorageDirectory)){
Toast.makeText(this,"Failed creating Directory!",Toast.LENGTH_SHORT).show();
}else{
File filename=new File(externalStorageDirectory, String.valueOf(Calendar.getInstance().getTimeInMillis())+".PNG");
FileOutputStream out = null;
try {
out = new FileOutputStream(filename);
cropped.compress(Bitmap.CompressFormat.PNG, 100, out); // cropped is your Bitmap instance
// PNG is a lossless format, the compression factor (100) is ignored
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
Intent returnIntent = new Intent();
returnIntent.putExtra("picture", Uri.fromFile(filename));
setResult(RESULT_OK, returnIntent);
finish();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
//Toast.makeText(this,mCropImageUri.toString(),Toast.LENGTH_SHORT).show();
}
And Activity A had:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == 999 && resultCode==RESULT_OK) {
Uri path=data.getParcelableExtra("picture");
Bitmap bitmap=null;
try {
bitmap= MediaStore.Images.Media.getBitmap(this.getContentResolver(), path);
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(this,path.toString(),Toast.LENGTH_SHORT).show();
if (bitmap!=null){
iv_profile_pic.setImageBitmap(bitmap);
}
}
Maybe my problem statement is wrong, but workaround works. Any edits/suggestions
are 100% welcome. Just in-case someone like me gets stuck, this might help!

android finish sometimes restarting app

I'm working on an app which allows user to choose a picture from gallery and then I start a activity to crop it.
I want to send the cropped image back to calling activity.
Both activities extend AppCompatActivity.
Calling activity:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
// start image crop activity
String dataString = data.getDataString();
Intent intent=new Intent(this, CropPhotoActivity.class);
intent.putExtra("SELECTED_PICTURE_FOR_CROP", dataString);
startActivityForResult(intent, CROP_PICTURE);
}
else if(requestCode == CROP_PICTURE) {
// get cropped bitmap
Bitmap bitmap = (Bitmap) data.getParcelableExtra("CROPPED_IMAGE");
profilePhoto.setImageBitmap(bitmap);
}
}
}
In the crop image activity, I have a button, which on click should return back to calling activity:
Button okButton = (Button)findViewById(R.id.ok_button);
okButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent returnIntent = new Intent();
returnIntent.putExtra("CROPPED_IMAGE", cropped_bitmap);
setResult(RESULT_OK, returnIntent);
finish(); // sometimes restarts app
}
});
Sometimes the bitmap gets returned correctly whereas sometimes it does not and the app gets restarted without error. Why is this happening? Does putExtra have anything to do with bitmap size or anything else?
You could try substituting
AppcompatActivity.this.finish()
(where AppcompatActivity is your class name)
for:
finish(); // sometimes restarts app
Or, create a method in the calling Activity:
public static void cropComplete(Activity activity)
{
activity.startActivity(activity, AnotherActivity.class);
activity.finish();
}
Theres's a limit for data length passed as extra in a intent. Try not passing the dataString value; instead you should save the image as a temporary file, pass the path in the intent and then load the image from your calling activity (or you can just save the dataString in a static helper class).
In the crop activity (saving bitmap code from Save bitmap to location):
// Save bitmap
String filename = "tempImage.png";
File sd = Environment.getExternalStorageDirectory();
File dest = new File(sd, filename);
FileOutputStream out = null;
try {
out = new FileOutputStream(dest);
bmp.compress(Bitmap.CompressFormat.PNG, 100, out); // bmp is your Bitmap instance
// PNG is a lossless format, the compression factor (100) is ignored
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null)out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// Get image file path
String path = dest.getAbsolutePath();
// Set result with image path
Intent returnIntent = new Intent();
returnIntent.putExtra("CROPPED_IMAGE_PATH", path);
setResult(RESULT_OK, returnIntent);
finish();
In the caller activity:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if(requestCode == CROP_PICTURE) {
// Get image file path
String imagePath = data.getStringExtra("CROPPED_IMAGE_PATH");
// Load image
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
}
}

Android 'set As Wallpaper' functionality

I am developing an application in which I have an image gallery and when I click on any image, it opens in full mode. But I want the set As Wallpaper functionality like android default gallery:
I know it can be done by custom code (setting wallpaper and cropping image). But I want to pass that image to android default wallpaper setter so that android will manage the cropping and setting wallpaper task. How can I do that? How can I pass that image to android default walpaper setter?
You can launch Crop intent by start activity for result and retrieve it in result and then use wallpaper manager class.
like this
Uri imgUri=Uri.parse("android.resource://your.package.name/"+R.drawable.image);
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(imgUri, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 80);
intent.putExtra("outputY", 80);
intent.putExtra("return-data", true);
startActivityForResult(intent, REQUEST_CODE_CROP_PHOTO);
and use Wallpaper manager in your onResult function
Also keep in mind that It depends on the device whether that device is support it or not. This Intent action is not part of the internal API. Some manufacturers provide their own Gallery apps and so there is no way of knowing whether or not the user's device will recognize the Intent.
This is my code which downloads a image from a URL.You can find it useful.Don't forget to add the required permissions for storage,wallpaper and internet.
#Override
public void onClick(View v) {
setWall(v);
}
});
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (shouldShowRequestPermissionRationale(
Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Explain to the user why we need to read the contacts
}
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
// MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE is an
// app-defined int constant that should be quite unique
return;
}
}
public void setWall(View view) {
new SetWallpaperTask().execute();
}
public class SetWallpaperTask extends AsyncTask <String, Void, Bitmap> {
String image = getIntent().getStringExtra("image");
ProgressDialog progressDialog;
#TargetApi(Build.VERSION_CODES.KITKAT)
#Override
protected Bitmap doInBackground(String... params) {
Bitmap result= null;
try {
result = Picasso.with(getApplicationContext())
.load(image)
.get();
} catch (IOException e) {
e.printStackTrace();
}
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
//new Intent(wallpaperManager.getCropAndSetWallpaperIntent(getImageUri(result,getApplicationContext())));
return result;
}
#TargetApi(Build.VERSION_CODES.KITKAT)
#Override
protected void onPostExecute (Bitmap result) {
super.onPostExecute(result);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getBaseContext());
{
startActivity(new Intent(wallpaperManager.getCropAndSetWallpaperIntent(getImageUri(result,getApplicationContext()))));
// wallpaperManager.setBitmap(result);
progressDialog.dismiss();
// Toast.makeText(getApplicationContext(), "Set wallpaper successfully", Toast.LENGTH_SHORT).show();
}}
#Override
protected void onPreExecute () {
super.onPreExecute();
progressDialog = new ProgressDialog(Wallpaper_activity.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCancelable(false);
progressDialog.show();
}
}
private Uri getImageUri(Bitmap inImage, Context inContext) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(),
inImage, "Title", null);
return Uri.parse(path);
}

ImageView not refreshing/reflecting changes

I'm using a photo picker intent to choose an image and write it to an application-private file. Most of my important source code is shown below. Once I press a button and perform the first image selection intent, then it successfully updates the image view. However, once I press the image selection button again (in the same activity), then the image view does NOT update, unless I exit and restart the activity. So I know the image is getting successfully saved, but why would the ImageView in the layout not refresh or update?
public void onResume() {
super.onResume();
ImageView myImageView = (ImageView)findViewById(R.id.contact_image);
if (hasImage) {
myImageView.setImageURI(Uri.fromFile(getFileStreamPath(TEMP_PHOTO_FILE)));
}
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case PHOTO_PICKED:
if (resultCode == RESULT_OK) {
if (data != null) {
Bundle extras = data.getExtras();
if (extras != null) {
hasImage = true;
bmp = (Bitmap) extras.get("data");
}
}
}
break;
}
}
private OnClickListener mChooseImage = new OnClickListener() {
#Override
public void onClick(View v) {
try {
// Launch picker to choose photo for selected contact
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", ICON_SIZE);
intent.putExtra("outputY", ICON_SIZE);
intent.putExtra("scale", true);
intent.putExtra("return-data", false);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile()));
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(intent, PHOTO_PICKED);
} catch (ActivityNotFoundException e) {
// LOG THIS
}
}
};
private File getTempFile() {
try {
if (!hasImage) {
FileOutputStream fos = openFileOutput(TEMP_PHOTO_FILE, MODE_WORLD_WRITEABLE);
fos.close();
}
return getFileStreamPath(TEMP_PHOTO_FILE);
} catch (FileNotFoundException e) {
// To be logged later
return null;
} catch (IOException e) {
// To be logged later
return null;
}
}
upon activity result, I set the ImageView's image URI to this file.
When it first completes, the ImageView changes to reflect this. However, if I attempt to choose the image again (same activity), the ImageView will not update until I exit and re-enter the activity. I'm not sure why this happens, is it because I'm trying to write to the temp.jpg everytime? Or do I need to refresh my layout somehow to reflect changes in the ImageView?
Judging by the ImageView source code, the ImageView won't reload the image if you call setImageURI with the same URI. You could try changing the URI by writing your image to another file.
ImageView will not redraw if "new" URI is the same like old one. "View.invalidate()" will not work. To "force" update you can do:
public void onResume() {
super.onResume();
ImageView myImageView = (ImageView)findViewById(R.id.contact_image);
if (hasImage) {
myImageView.setImageDrawable(null); // <--- added to force redraw of ImageView
myImageView.setImageURI(Uri.fromFile(getFileStreamPath(TEMP_PHOTO_FILE)));
}
}
invalidate() not worked. Try hack :
imageView.setImageURI(null);
imageView.setImageURI(newUri);
To force redrawing your widget/View just call View.invalidate();
I had a similar problem where I was using the devices camera to take a picture and then wanting the imageView in the original screen to refresh when I returned to it. The solution was to call View.invalidate() in onResume().
For me, it refreshed my ImageView with this
#Override
public void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_PHOTO && resultCode == RESULT_OK && data != null && data.getData() != null) {
filePath = data.getData();
try {
mProfilePic.setImageURI(null);
mProfilePic.setImageURI(filePath);
Bitmap imageBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
mProfilePic.setImageBitmap(imageBitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
I would suggest this thing solution. After trying lot of solutions i found this one worked for me.
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
//Do something after 1000ms
ivProfilePic.setImageBitmap(bitImage);
}
}, 1000);
UIView.transition(with: bannerImageView, duration: 0.3, options: [.transitionCrossDissolve], animations: { [weak self] in
self?.exampleImageView.image = newImage
})
Use this func in your view controller
If you are also setting the image using Glide then check if the url is setting up the image or not. If the Glide fails and sets the error Image then setImageURI won't change the image.
This happened in one of my projects. I though this might help someone.

Android: NPE happens when getting picture from camera

I have a problem on my Android app. I'm using MediaStore.ACTION_IMAGE_CAPTURE intent to take picture from camera. It worked all most of devices but I got the following crash errors on DroidX device from android market.
I think imageCaptureUri can not be null in this case. So it is not the cause.
Do you have any ideas? Is it a firmware error?
java.lang.NullPointerException at
android.content.ContentResolver.openInputStream(ContentResolver.java:286)
at
com.eb.android.activity.AddActivity.getBase64Receipt(AddActivity.java:193)
at
com.eb.android.activity.AddActivity.publishReceipt(AddActivity.java:204)
at com.eb.android.activity.AddActivity.access$0(AddActivity.java:203)
at com.eb.android.activity.AddActivity$1.run(AddActivity.java:50) at
java.lang.Thread.run(Thread.java:1102)
java.lang.NullPointerException at
android.content.ContentResolver.openInputStream(ContentResolver.java:288)
at
com.eb.android.activity.AddActivity.getBase64Receipt(AddActivity.java:193)
at
com.eb.android.activity.AddActivity.publishReceipt(AddActivity.java:204)
at com.eb.android.activity.AddActivity.access$0(AddActivity.java:203)
at com.eb.android.activity.AddActivity$1.run(AddActivity.java:50) at
java.lang.Thread.run(Thread.java:1096)
This is my implementation:
public class AddActivity extends Activity {
public static final int TAKE_RECEIPT = 2;
private Uri imageCaptureUri;
private Runnable submitReceiptRunnable = new Runnable() {
public void run() {
publishReceipt();
}
};
private ProgressDialog progressDialog;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add);
registerListeners();
}
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (TAKE_RECEIPT):
takeReceiptCallback(resultCode, data);
break;
}
}
private void registerListeners() {
ImageView addReceiptButton = (ImageView) findViewById(R.id.AddReceiptButton);
addReceiptButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
takePictureFromCamera();
}
});
}
private void takePictureFromCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "tmp_receipt_"
+ String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageCaptureUri);
intent.putExtra("return-data", true);
startActivityForResult(intent, TAKE_RECEIPT);
}
private void takeReceiptCallback(int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
submitReceipt();
}
}
private void submitReceipt() {
Thread thread = new Thread(null, submitReceiptRunnable);
thread.start();
progressDialog = ProgressDialog.show(this, "Please wait...", "Publishing receipt ...", true);
}
private String getBase64Receipt() {
try {
InputStream inputStream = getContentResolver().openInputStream(imageCaptureUri);
byte[] bytes = CommonUtil.getBytesFromInputStream(inputStream);
return Base64.encodeBytes(bytes);
} catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
}
return null;
}
private void publishReceipt() {
String receipt = getBase64Receipt();
...
}
}
Are you sure that image crop mode forcing
intent.putExtra("return-data", true);
works correctly for the device you use. Correct me if I am wrong, but it is not safe and not well documented approach. Here you can find example of working code without cropping.
UPDATE: Issue you are facing with has long history, also at SO:
https://stackoverflow.com/questions/3904685/unable-to-find-com-android-camera-cropimage-activity-in-android
Issue I experienced was using crop immediatelly after image was taken by the camera. Also, it is not compatible through different Android versions, so if you get it working for 1.5 maybe it will not work for 2.3. Definitely something is wrong, as may be concluded from the Android Developer Group posts:
http://groups.google.com/group/android-developers/browse_thread/thread/2dd647523926192c/569f36b5b28f2661?lnk=gst&q=Crop+image+intent#569f36b5b28f2661
http://groups.google.com/group/android-developers/browse_thread/thread/2dd647523926192c/dcbe5aef29eddad6?lnk=gst&q=Crop+image+intent#dcbe5aef29eddad6
http://groups.google.com/group/android-developers/browse_thread/thread/d7b6a133c164aa17/184bf3b85da2ce58?lnk=gst&q=Crop+image+intent#184bf3b85da2ce58

Categories

Resources