Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

84
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda