I want to let user capture image from camera and upload to server. So, I need an image file from captured photo.
I searched for many solutions but none of them worked.
I tried following:
Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (camera_intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(camera_intent, 1);
}
in onActivityResult:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent dataIntent) {
super.onActivityResult(requestCode, resultCode, dataIntent);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == 1) {
Bundle dataBundle = dataIntent.getExtras();
Bitmap imageBitmap = (Bitmap) dataBundle.get("data");
img_profile.setImageBitmap(imageBitmap); //getting thumbnail and setting to preview image
try{
Uri selectedImageUri = dataIntent.getData();
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getActivity().getContentResolver().query(selectedImageUri, projection, null, null,null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String filePath = cursor.getString(column_index);
profilePicFile = new File(filePath);
cursor.close();
}
catch (Exception e){
e.printStackTrace();
}
but my I got nullPinterException saying that Uri is null
. I tried almost all solutions on web but didn't work. Can anyone have any solution for this?