Android and JS mixed (JS call Android camera)

Source: Internet
Author: User

Refer to Android camera call, http://blog.csdn.net/yanzi1225627/article/details/33028041/, thank you

How to call the camera do not repeat, the following is the JS call camera code:

Java:

1**2* Created by Administrator on 2016/6/24 0024.3*/4  Public classQrcodehtmlactivityextendsActivity {5     /**6 * Web page7      */8     PrivateWebView Wvqrcode;9 @OverrideTen     protected voidonCreate (Bundle savedinstancestate) { One         Super. OnCreate (savedinstancestate); A Setcontentview (r.layout.activity_html_qrcode); - Initview (); - Setwebview (); the     } -  -     Private voidInitview () { -Wvqrcode =(WebView) Findviewbyid (r.id.wv_qrcode); +     } -  +     /** A * Set Page at      */ -     Private voidSetwebview () { -         //allow JavaScript to execute -Wvqrcode.getsettings (). setjavascriptenabled (true); -         //passing objects to JS -Wvqrcode.addjavascriptinterface (NewShowcamera (), "Camera"); in         //the small partner of node can be saved to assets -         //wvqrcode.loadurl ("File:///android_asset/qrcode.html "); to         //Visit Web pages +Wvqrcode.loadurl ("http://192.168.253.1:3000/htmls/QRCode.html"); -     } the      Public Final classShowcamera { *         //HTML calls this method to pass the data, the annotations must be kept, otherwise it will go wrong. $ @JavascriptInterfacePanax Notoginseng          Public voidShowcamera () { -Intent Intent =NewIntent (qrcodehtmlactivity. This, Qrcodesurfaceactivity.class); the             //call to open the camera's interface +Qrcodehtmlactivity. This. StartActivity (intent); A         } the     } +}

Html:

1 <!DOCTYPE HTML>2 <HTML>3 <Head>4     <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />5     <title>Two-dimensional code call</title>6     <Scripttype= "Text/javascript">7         functionShowqrcode () {8 Window.camera.showCamera ();9         }Ten     </Script> One </Head> A <Body> - <H3>This example is a click button to call the camera scan QR code</H3> - <inputtype= "button"name=""value= "click Invoke"onclick= "Javascript:showqrcode ()"/> the </Body> - </HTML>

Github:https://github.com/weifengzz/androidjsqrcode

Android and JS mixed (JS call Android camera)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.