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