WebViewJavascriptBridge


Source link: https://github.com/fangj/WebViewJavascriptBridge

WebViewJavascriptBridge

Cross-platform WebViewJavascriptBridge for HTML/Android/Chrome Extension, the javascript interface compatible with WebViewJavascriptBridge

TODO:

  • Use the queue ,cache the message before the client and server both inited.
  • Use the Long-lived connections instead of the Simple one-time requests, Message Passing

Android

To use a WebViewJavascriptBridge in your Android project:

  1. Add "res/raw/webviewjavascriptbridge.js" and "com/fangjian/WebViewJavascriptBridge.java" to your project

  2. Set up the Android side

    bridge=new WebViewJavascriptBridge(this.getApplicationContext(),webView,new UserServerHandler()) ;

    class UserServerHandler implements WebViewJavascriptBridge.WVJBHandler{ @Override public void handle(String data, WebViewJavascriptBridge.WVJBResponseCallback jsCallback) { Log.d("test","Received message from javascript: "+ data); if (null !=jsCallback) { jsCallback.callback("Java said:Right back atcha"); } bridge.send("I expect a response!",new WebViewJavascriptBridge.WVJBResponseCallback() { @Override public void callback(String responseData) { Log.d("test","Got response! "+responseData); } } ); bridge.send("Hi"); } }

    bridge.registerHandler("handler1",new WebViewJavascriptBridge.WVJBHandler() { @Override public void handle(String data, WebViewJavascriptBridge.WVJBResponseCallback jsCallback) { Log.d("test","handler1 got:"+data); if(null!=jsCallback){ jsCallback.callback("handler1 answer"); } bridge.callHandler("showAlert","42"); } } );

  3. Set up the Javascript side

    console.log("user_client.js called!"); document.addEventListener('WebViewJavascriptBridgeReady' , function(event) { var bridge=event.bridge; bridge.init(function(message, responseCallback) { if (responseCallback) { responseCallback("Right back atcha") ; } } ) ; bridge.send('Hello from the javascript'); bridge.send('Please respond to this', function(responseData) { console.log("Javascript got its response "+ responseData); } ); bridge.registerHandler("showAlert", function(data) { console.log("alert:"+data); } ); bridge.callHandler("handler1","gift for handler1",function(responseData){ console.log("got handler1 response:"+responseData); } ); } , false)

Chrome

To use a WebViewJavascriptBridge in your chrome extension:

  1. Add "bridgeClientChrome.js" and "bridgeServerChrome.js" to your manifest.json

    "content_scripts": [ { "matches": [" :///*"], "js": ["user_client.js","bridgeClientChrome.js"] } ], "background": { "scripts": ["bridgeServerChrome.js","user_server.js"] } ,

  2. Set up the background side:

    console.log("user_server.js called!"); bridge.sinit(function(data,responseCallback){ console.log("Received message from javascript: "+data); responseCallback("Right back atcha"); } )

    bridge.ssend("Well hello there"); bridge.ssend("Give me a response, will you?", function(responseData) { console.log("Background got its response! "+responseData); } )

  3. Set up the foreground side:

    console.log("user_client.js called!"); document.addEventListener('WebViewJavascriptBridgeReady', function onBridgeReady(event) { var bridge = event.bridge bridge.init(function(message, responseCallback) { alert('Received message: ' + message)
    if (responseCallback) { responseCallback("Right back atcha") } } ) bridge.send('Hello from the javascript') bridge.send('Please respond to this', function responseCallback(responseData) { console.log("Javascript got its response", responseData) } ) } , false)

HTML

To use a WebViewJavascriptBridge in your HTML page:

  1. Add "bridgeServerHtml.js" and "bridgeClientHtml.js" to your page. bridgeServerHtml.js Must be first and bridgeClientHtml.js Must be last.

    <script src="bridgeServerHtml.js"></script> <script src="user_client.js"></script> <script src="user_server.js"></script> <script src="bridgeClientHtml.js"></script>
  2. Set up the background side:

    console.log("user_server.js called!"); bridge.sinit(function(data,responseCallback){ console.log("Received message from javascript: "+data); if(responseCallback){ responseCallback("Right back atcha"); } } ) function serverSend(){ bridge.ssend("Well hello there"); bridge.ssend("Give me a response, will you?", function(responseData) { console.log("Background got its response! "+responseData); } ) } setTimeout(serverSend,1000);

  3. Set up the foreground side:

    console.log("user_client.js called!"); document.addEventListener('WebViewJavascriptBridgeReady', function onBridgeReady(event) { var bridge = event.bridge bridge.init(function(message, responseCallback) { alert('Received message: ' + message)
    if (responseCallback) { responseCallback("Right back atcha") } } ) bridge.send('Hello from the javascript') bridge.send('Please respond to this', function responseCallback(responseData) { console.log("Javascript got its response", responseData) } ) } , false)

IOS

An iOS/OSX bridge for sending messages between Obj-C and JavaScript in UIWebViews/WebViews.

forked from marcuswestin/WebViewJavascriptBridge.

Resources

This library aims to provide a chat UI view.

  • You need to write just few code to create chat view
  • Easy to use for a chat app

SectionedMergeAdapter is a library based on MergeAdapter by CommonsWare. It allows you to work with sections and subheaders in your ListViews. With this library, you get the advantage of stitching together the rows and the header of the subsection in the subsection itself. For example, if there are no rows in a subsection of the ListView, the header of the subsection is also not shown.

One tool to manage key generation, key storing and encryption on different APIs of Android.

As you may know android provided API to use keystore that is stored in system only from API 18. They introduced AndroidKeyStore provider that is responsible to manage this.

But as always there are underwater stones. Up to API 23 you are only able to create asymmetric keys using AndroidKeyStore provider. Also algorithms that you can use are limited. And what about devices below API 18 ?

This project provides API that wraps default JCA api and AndroidKeyStore API and makes it easy to create, manage and use your keys on any andorid API.

Fontometrics is an Android library which help to use customs font with just writing one line of code avoiding all the hassle to add the .ttf/.otf font files in the assests folder.

Library to help developers build full MVP apps.

A showcase to demonstrate how to use MVP with RXAndroid.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes