7
How to build your own Hybrid JS Interface with Android? By Swagat Parida Webview <----> Native JS

How to build your own Hybrid JS Interface with Android?

Embed Size (px)

Citation preview

Page 1: How to build your own Hybrid JS Interface with Android?

How to build your own Hybrid JS Interface with Android?

By Swagat Parida

Webview <----> Native JS

Page 2: How to build your own Hybrid JS Interface with Android?

Introduction

Sample Android app with JS <-> WebView <-> Native communication. This application explains about base communication between JavaScript and Native code in Android. Also, this sample app has WebView implementation using JavascriptInterface implementation.

Background

How does hybrid mobile app framework work behind the scenes? How does WebView communicate with JS/Web pages?

Page 3: How to build your own Hybrid JS Interface with Android?

Using the CodeThe below steps will let us create a base framework which allows a native app to communicate with JavaScript or WebView components.

STEP 1: Create JavascriptInterface Class

Page 4: How to build your own Hybrid JS Interface with Android?

STEP 2: Create WebView Activity

Webview JS Injection

Page 5: How to build your own Hybrid JS Interface with Android?

STEP 3: JS Functions to Call Native Implementations

Plugin Callback Handler

Page 6: How to build your own Hybrid JS Interface with Android?

STEP 4: Manifest Settings

STEP 5: Assets Directory

The complete sample app and source code can be downloaded @https://github.com/swagatblog/WebViewJSBridgeAndroid.

Page 7: How to build your own Hybrid JS Interface with Android?

???

??

?

? ??

??

???

? ??

??Please contact

Swagat Parida