Mi problema es cuando pulso en el enlace <a href=""> o un <button> carga el mensaje 'Load camera...' pero automáticamente se cierra la app. Y no muestra lo típico de "La app se cerró inesperadamente"
Código:
Javascript: mWebView.addJavascriptInterface(new WebViewInterface(), "MainActivityInterface"); public class WebViewInterface{ @JavascriptInterface public void showToast(){ Toast toast1 = Toast.makeText(getApplicationContext(), "Load camera...", Toast.LENGTH_SHORT); toast1.show(); launchQRScanner(); } } public void launchQRScanner(View v) { if (isCameraAvailable()) { Intent intent = new Intent(this, ZBarScannerActivity.class); intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE}); startActivityForResult(intent, ZBAR_SCANNER_REQUEST); } else { Toast.makeText(this, "Cámara no disponible", Toast.LENGTH_SHORT).show(); } } public boolean isCameraAvailable() { PackageManager pm = getPackageManager(); return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case ZBAR_SCANNER_REQUEST: if (resultCode == RESULT_OK) { Toast.makeText(this, "Scan Result = " + data.getStringExtra(ZBarConstants.SCAN_RESULT), Toast.LENGTH_SHORT).show(); } else if(resultCode == RESULT_CANCELED && data != null) { String error = data.getStringExtra(ZBarConstants.ERROR_INFO); if(!TextUtils.isEmpty(error)) { Toast.makeText(this, error, Toast.LENGTH_SHORT).show(); } } break; } }
Código HTML:
<script> function showAndroidToast(){ MainActivityInterface.showToast(); } </script>