0

I followed the post from
https://stackoverflow.com/a/10168114/5078763
and
http://www.theappguruz.com/blog/android-take-photo-camera-gallery-code-sample
edited the code as below

My App is crashing at

MediaStore.Images.Media.getBitmap

It executes below Bfr Log

Log.d("TAG", "onActivityResult: bfr");

But not Afr Log

Log.d("TAG", "onActivityResult: Afr");

My Completed Code as below :

void calGlryImjPkrFnc()
{
    Intent glrImjPkrVar = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    glrImjPkrVar.setType("image/*");
    startActivityForResult(glrImjPkrVar , 1);
}

void calCamImjPkrFnc()
{
    Intent camImjPkrVar = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(camImjPkrVar, 2);
}

protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent)
{
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

    Bitmap pkdImjBitmapVar = null;

    if(requestCode == 1 && resultCode == RESULT_OK)
    {
        Log.d("TAG",requestCode + "");
        if (imageReturnedIntent != null)
        {
            try
            {

                ContentResolver contntMgrVaj = getApplicationContext().getContentResolver();
                Uri uriVaj = imageReturnedIntent.getData();

                Log.d("TAG", "onActivityResult: bfr");

                pkdImjBitmapVar = MediaStore.Images.Media.getBitmap(contntMgrVaj, uriVaj);

                Log.d("TAG", "onActivityResult: Afr");

            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
    }
    else if(requestCode == 2 && resultCode == RESULT_OK)
    {
        pkdImjBitmapVar = (Bitmap) imageReturnedIntent.getExtras().get("data");
    }

    imjVyuVar.setImageBitmap(pkdImjBitmapVar);
}

Help me to Fix this crash

Community
  • 1
  • 1
Sujay U N
  • 4,974
  • 11
  • 52
  • 88

2 Answers2

1

Post full crash log first.

However, check if uriVaj is not null and your application permission.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
You Kim
  • 2,355
  • 1
  • 10
  • 11
0
void calCamImjPkrFnc() {
    File image = new File("Your path you want to save file");
    Uri uriSavedImage = Uri.fromFile(image);
    Intent camImjPkrVar = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); 
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uriSavedImage); 
    startActivityForResult(camImjPkrVar, 2);
}

By add "android.provider.MediaStore.EXTRA_OUTPUT" work for me, hope it help you.

squalle0nhart
  • 351
  • 1
  • 6