android / views-widgets-samples

Multiple samples showing the best practices in views-widgets on Android.
Apache License 2.0
5.06k stars 3.01k forks source link

Adds a class to determine which JS-Java API to use #149

Closed gcoleman799 closed 4 years ago

gcoleman799 commented 4 years ago

This PR creates a new method in MainActivity.kt called 'createJsObject'. If the version of WebView that the application is using can use WebMessageListener then it will be preferred for security reasons. Otherwise the application will defer to WebAppInterface. The method allows for the JavaScript side of the application to remain unaware of the version fo WebView that it is running on as it contains logic which manipulates the behavior of WebAppInterface to mirror the behavior of WebMessageListener. For example createJsObject makes it so that WebMessageListener contains a method postMessage() and runs on the UI thread.