Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

80
Views
Webview retrieve captured image on startActivityForResult

I would like to capture images (2) then retrieve the captured image into an webview element.

I decided to open camera in WebAppInterface

@JavascriptInterface
public String openCamera() {
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    WEB_APP = 1;
    startActivityForResult(intent, CAMERA_PIC_REQUEST);
    while(WEB_APP == 1) {}
    if(imageBase64!=null) WEB_APP=0;
    return imageBase64;
}

Then on startActivityForResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if(requestCode == CAMERA_PIC_REQUEST){
        try {
            Bitmap image = (Bitmap) intent.getExtras().get("data");
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            image.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
            byte[] byteArray = byteArrayOutputStream.toByteArray();
            String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
            imageBase64 = encoded;
        }catch (Exception e){
            Toast.makeText(getApplicationContext(),"No file selected",Toast.LENGTH_LONG).show();
        }
    }
    WEB_APP = 0;
}

I retrieve the image, assign it to static String imageBase64 then return it a value in openCamera()

This process is working fine, where am having a problem i cannot attach two images, once i select first image on second image capture, the code is retrieving nothing and the app become unusable.

Please help where am getting things wrongly

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!