Upgrade to Pro — share decks privately, control downloads, hide ads and more …

webMessaging

 webMessaging

funnelbit

July 14, 2015
Tweet

More Decks by funnelbit

Other Decks in Technology

Transcript

  1. "OESPJE.͔Βͷ 8FC.FTTBHJOH JEGVOOFMCJU

  2. ͜Μʹͪ͸ w JEGVOOFMCJU w ๺ଜɹྋ

  3. +4ͱ+BWBͷ௨৴

  4. ݱঢ়ͷ+4ͱͷ௨৴ +4ʹ౉͢ mWebView.loadUrl( "javascript:document.getElementById('content').innerHTML=\ "͜Μʹͪ͸\""); mWebView.evaluateJavascript(
 "var content = document.getElementById('content');"

    +
 "content.innerHTML = \"͜Μʹͪ͸\""
 , null); w "1*-FWFMd
  5. ͜Ε·Ͱͷ+4ͱͷ௨৴ +4͔Βड͚औΔ mWebView.addJavascriptInterface(new JavaScriptInterface(), “Callback"); private class JavaScriptInterface {
 @JavascriptInterface


    public void onEdit(String text) {
 // ͜Μʹͪ͸
 }
 }
  6. ໘౗ w +4ʹͪΐͬͱ஋Λ౉͚ͩ͢Ͱ΋͍͢͝खؒ w จࣈྻͳ+4͕+BWB಺ʹฆΕࠐΉ

  7. )5.-8FC.FTTBHJOH w JGSBNFXJOEPXؒͷ௨৴ΛՄೳͱ͢Δ w QPTU.FTTBHF w .FTTBHF$IBOOFMΛར༻ͨ͠ QPTU.FTTBHF

  8. QPTU.FTTBHF JGSBNFTSDlEPNFJOzJGSBNF ʜ WBSJGSBNFEPDVNFOUHFU&MFNFOU#Z*E QBHF  JGSBNFDPOUFOU8JOEPXQPTU.FTTBHF ͜Μʹͪ͸ lEPNBJOl 

    WBSSFDFJWF.FTTBHFGVODUJPO FWFOU \ DPOTPMFMPH PL  ^ XJOEPXBEE&WFOU-JTUFOFS NFTTBHF SFDFJWF.FTTBHF  w QBHF w QBHF
  9. QPTU.FTTBHF NFTTBHFDIBOOFM WBSSFDFJWF.FTTBHFGVODUJPO FWFOU \ WBSQPSUFWFOUQPSUT<> QPSUTUBSU  QPSUQPTU.FTTBHF ͋Γ͕ͱ͏

     ^ XJOEPXBEE&WFOU-JTUFOFS NFTTBHF SFDFJWF.FTTBHF GBMTF  w QBHF w QBHF WBSDIBOOFMOFX.FTTBHF$IBOOFM  WBSJGSBNFEPDVNFOUHFU&MFNFOU#Z*E QBHF  WBSQPSUDIBOOFMQPSU QPSUTUBSU  QPSUBEE&WFOU-JTUFOFS NFTTBHF GVODUJPO F \ DPOTPMFMPH Αͬ͠Ό  ^  JGSBNFDPOUFOU8JOEPXQPTU.FTTBHF ͜Μʹͪ͸  <DIBOOFMQPSU> 
  10. 8FC.FTTBHF༻ Ϋϥεͱϝιου w BOESPJEXFCLJU w 8FC.FTTBHF w 8FC.FTTBHF1PSU w 8FC.FTTBHF1PSUQPTU.FTTBHF

    w 8FC.FTTBHF1PSU8FC.FTTBHF$BMMCBDL w BOESPJEXFCLJU8FC7JFX w 8FC7JFXDSFBUF8FC.FTTBHF$IBOOFM w 8FC7JFXQPTU8FC.FTTBHF
  11. w ૹ৴͢ΔϝοηʔδΛදͨ͠Ϋϥε WebMessage webMessage = new WebMessage("͜Μʹͪ͸"); w .FTTBHF1PSUTΛҾ਺ʹऔΕΔ WebMessage

    webMessage = new WebMessage("portͩΑ", ports); 8FC.FTTBHF
  12. w .FTTBHF$IBOOFMͰ࢖͏ϙʔτ w +4ͷ.FTTBHF$IBOOFMQPSUPS .FTTBHF$IBOOFMQPSU૬౰ 8FC.FTTBHF1PSU

  13. w .FTTBHF$IBOOFMͰQPTU͢Δ mWebMessagePort1.postMessage(webMessage); 8FC.FTTBHF1PSU QPTU.FTTBHF 8FC.FTTBHF

  14. w .FTTBHF$IBOOFMͰड৴ͨ͠಺༰Λड͚औΔ port1.setWebMessageCallback(new WebMessagePort.WebMessageCallback() {
 @Override
 public void onMessage(WebMessagePort port,

    WebMessage message) {
 super.onMessage(port, message);
 Log.e("onMessage", message.getData());
 }
 }); 8FC.FTTBHF1PSU8FC.FT TBHF$BMMCBDL
  15. w .FTTBHF$IBOOFMΛ࡞Δ w ഑ྻͰQPSU͕ͭฦͬͯ͘Δ mWebMessagePorts = mWebView.createWebMessageChannel();
 WebMessagePort port1 =

    mWebMessagePorts[0];
 WebMessagePort port2 = mWebMessagePorts[1]; 8FC7JFX DSFBUF8FC.FTTHF$IBOOFM
  16. w 8FC7JFXͰදࣔதͷ1BHFʹQPTU.BTTBHF͢Δ mWebView.postWebMessage(webMessage, uri); 8FC7JFX QPTU8FC.FTTBHF

  17. ྫ mWebMessagePorts = mWebView.createWebMessageChannel();
 WebMessagePort port1 = mWebMessagePorts[0];
 WebMessagePort port2

    = mWebMessagePorts[1]; … port1.setWebMessageCallback(new WebMessagePort.WebMessageCallback() { … }}); … WebMessagePort[] ports = {port2};
 WebMessage webMessage = new WebMessage("͜Μʹͪ͸portsͰ͢ ", ports);
 mWebView.postWebMessage(webMessage, uri);
  18. ·ͱΊ w +BWB಺ʹจࣈྻͳ+4͕ฆΕࠐ·ͳ͍ w )5.-ͷඪ४ͳͷͰ൚༻త w ·ͩQSFWJFXஈ֊Ͱมߋ͕ଟ͍ͷͰ஫ҙ QSFWJFXQPTU.FTTBHF5P.BJO'SBNF QSFWJFXQPTU8FC.FTTBHF

  19. ͋Γ͕ͱ͏͍͟͝·ͨ͠