My problem is that every time i choose third party camera application for example Beauty Plus Camera i got null pointer exception every time, my code is completely working for default camera application it even works with Google's new camera made for moto series phones.
Very first time dialog to choose option for gallery or camera is here:
private void OpenDialogForImage() {
final CharSequence[] items = {
"Gallary", "Camera", "Cancel"
};
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Do something with the selection
switch (item) {
case 0:
Intent intent1 = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent1.setType("image/*");
startActivityForResult(
Intent.createChooser(intent1, "Select File"),
SELECT_FILE);
break;
case 1:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);
break;
case 2:
break;
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
This is OnActivityResult() method:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Sponser_key && resultCode == Activity.RESULT_OK) {
String sSponsors = data.getStringExtra("Sponsors");
if (sSponsors != null)
sponsorsResp = new Gson().fromJson(sSponsors, GetSponsorsResp.class);
} else if (requestCode == REQUEST_CAMERA) {
if (resultCode == activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
ivProfile.setImageBitmap(photo);
// CALL THIS METHOD TO GET THE URI FROM THE BITMAP
Uri tempUri = Other.getImageUri(activity, photo);
file = new File(Other.getRealPathFromURI(activity, tempUri));
} else {
/**
* not select any image
*/
}
} else if (requestCode == SELECT_FILE) {
if (resultCode == activity.RESULT_OK) {
Uri selectedImageUri = data.getData();
ivProfile.setImageURI(selectedImageUri);
file = new File(Other.getPath(activity, selectedImageUri));
}
}
}
This above code is note working for some third party applications like i have mentioned before. I am getting NullPointerException in this line: Bitmap photo = (Bitmap) data.getExtras().get("data");