Skip to content

Instantly share code, notes, and snippets.

@Isabellle
Created December 13, 2016 08:27
Show Gist options
  • Save Isabellle/2f07519404981e9bfcce960b6ccb41f0 to your computer and use it in GitHub Desktop.
Save Isabellle/2f07519404981e9bfcce960b6ccb41f0 to your computer and use it in GitHub Desktop.
In html:
<input type="file" name="files[]" data-picture="2" id="pic2" class="pic2" onClick="showAndroidToast('identity')">
<script type="text/javascript">
function showAndroidToast(type) {
androidPicture.showToast(type);
}
</script>
In Android:
webView.addJavascriptInterface(new WebAppInterface(this), "androidPicture");
class WebAppInterface {
Context mContext;
public static String type;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
@JavascriptInterface
public void showToast(String type) {
Log.d("TAG", "Received: "+type);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment