SlideShare uma empresa Scribd logo
1 de 19
@sergiandreplace
• I do Android stuff
• I’ve tried to create something
with webviews
• It was a monster
• Pain and tears
• This is my history
@sergiandreplace
• “A view that displays web pages”
• Since API 1
• New version in KitKat (not today)
• Is not based on Chrome
• Renderer is “special”
• Its full of bugs and issues
@sergiandreplace
• WebView is added to a layout like any other view
• It’s a wrapper to execute html and associated
technologies
• The Java environment and the html environment are
isolated*
• We can:
• loadUrl(String url)
• loadData(String data, String mime, String encoding)
• loadDataWithBaseUrl (String baseUrl. String data….)
• android.permission.INTERNET!!
Android app
Webview
HTML
(JS, CSS, etc)
Java
@sergiandreplace
@sergiandreplace
• WebSettings settings=webView.getSettings()
• settings.
• setJavaScriptEnabled
• setGeolocationEnabled
• setJavaScriptCanOpenWindowsAutomatically
• setBuiltInZoomControls
@sergiandreplace
• Default behaviour: open links externally (yes, it’s true)
• We should intercept the url requests and redirect back to the
webview
• We need a WebViewClient
• WebViewClient handles page events
@sergiandreplace
@sergiandreplace
• WebViewClient handles page lifecycle and resources loading
• .onPageFinished (it’s a trap!)
• .onPageStarted
• .shouldInterceptRequest (ooooh!)
• WebChromeClient Just handles “other” events. More specific to page
itself* .
• .onProgressChanged (what the…?)
@sergiandreplace
• Android fragmentation is nothing compared to this
• Video full screen is handled by WebChromeClient.onShowCustomView
• Android <=2.3.3  view instanceof VideoView
• Android >3.0  view instanceof HTML5VideoView . An internal private class (d’oh!)
Field proxiedVideoFullScreen = callback.getClass().getDeclaredFields()[0];
proxiedVideoFullScreen.setAccessible(true);
Object unproxiedVideoFullScreen=proxiedVideoFullScreen.get(callback);
Field mUri= unproxiedVideoFullScreen.getClass().getSuperclass().getDeclaredField("mUri");
mUri.setAccessible(true);
path =((Uri)mUri.get(unproxiedVideoFullScreen)).toString();
@sergiandreplace
• Just put your web on assets and
load it
• loadUrl("file:///android_asset/...
(///!!!)
• Java vs. Javascript.Try to be as
biased as possible
• Do not mix interactive events
(touch, drag, etc)
@sergiandreplace
@sergiandreplace
• We can inject Java objects to the WebView
• This object methods can be invoked from JavaScript
• Cool, isn’t? So cool that nobody else supports it
• Forget DODM!
• Sooo…
@sergiandreplace
• Just use a specific url format and capture it from WebViewClient
and Use url to put parameters
• This works in all platforms
• Uri class is our best friend for parsing urls
• Returning values? Add callback function as parameter. All calls
are asynchronous
• Basically, this is what Cordova does
@sergiandreplace
@sergiandreplace
• Only one possible solution
• loadUrl(“javascript:….”);
• End of it
@sergiandreplace
@sergiandreplace
• Bug http://code.google.com/p/android/issues/detail?id=17535:Url with params not
working
• Sony (des)Experia
• Create a mini-browser to the web team. Don’t relay on Chrome for Android
• Abandon Android 3.0. Seriously.
• Do a lot of tests
• Hardware acceleration:“If your application performs custom drawing, test your
application on actual hardware devices with hardware acceleration turned on to find
any problems” a.k.a.: Just try
@sergiandreplace
• Questions and all the stuff

Mais conteúdo relacionado

Mais de Sergi Martínez

Kotlin, a modern language for modern times
Kotlin, a modern language for modern timesKotlin, a modern language for modern times
Kotlin, a modern language for modern timesSergi Martínez
 
What is flutter and why should i care?
What is flutter and why should i care?What is flutter and why should i care?
What is flutter and why should i care?Sergi Martínez
 
What is flutter and why should i care? Lightning talk
What is flutter and why should i care? Lightning talkWhat is flutter and why should i care? Lightning talk
What is flutter and why should i care? Lightning talkSergi Martínez
 
Let’s talk about star wars with Dialog Flow
Let’s talk about star wars with Dialog FlowLet’s talk about star wars with Dialog Flow
Let’s talk about star wars with Dialog FlowSergi Martínez
 
Database handling with room
Database handling with roomDatabase handling with room
Database handling with roomSergi Martínez
 
Introduction to Android Fragments
Introduction to Android FragmentsIntroduction to Android Fragments
Introduction to Android FragmentsSergi Martínez
 
Creating multillingual apps for android
Creating multillingual apps for androidCreating multillingual apps for android
Creating multillingual apps for androidSergi Martínez
 
Píldoras android i. Intro - 2ª parte
Píldoras android i. Intro - 2ª partePíldoras android i. Intro - 2ª parte
Píldoras android i. Intro - 2ª parteSergi Martínez
 

Mais de Sergi Martínez (9)

Kotlin, a modern language for modern times
Kotlin, a modern language for modern timesKotlin, a modern language for modern times
Kotlin, a modern language for modern times
 
What is flutter and why should i care?
What is flutter and why should i care?What is flutter and why should i care?
What is flutter and why should i care?
 
What is flutter and why should i care? Lightning talk
What is flutter and why should i care? Lightning talkWhat is flutter and why should i care? Lightning talk
What is flutter and why should i care? Lightning talk
 
Let’s talk about star wars with Dialog Flow
Let’s talk about star wars with Dialog FlowLet’s talk about star wars with Dialog Flow
Let’s talk about star wars with Dialog Flow
 
Database handling with room
Database handling with roomDatabase handling with room
Database handling with room
 
Smartphones
SmartphonesSmartphones
Smartphones
 
Introduction to Android Fragments
Introduction to Android FragmentsIntroduction to Android Fragments
Introduction to Android Fragments
 
Creating multillingual apps for android
Creating multillingual apps for androidCreating multillingual apps for android
Creating multillingual apps for android
 
Píldoras android i. Intro - 2ª parte
Píldoras android i. Intro - 2ª partePíldoras android i. Intro - 2ª parte
Píldoras android i. Intro - 2ª parte
 

Último

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

Último (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Android webviews and Hybrid Development. A Horror Story

  • 1.
  • 2. @sergiandreplace • I do Android stuff • I’ve tried to create something with webviews • It was a monster • Pain and tears • This is my history
  • 3. @sergiandreplace • “A view that displays web pages” • Since API 1 • New version in KitKat (not today) • Is not based on Chrome • Renderer is “special” • Its full of bugs and issues
  • 4. @sergiandreplace • WebView is added to a layout like any other view • It’s a wrapper to execute html and associated technologies • The Java environment and the html environment are isolated* • We can: • loadUrl(String url) • loadData(String data, String mime, String encoding) • loadDataWithBaseUrl (String baseUrl. String data….) • android.permission.INTERNET!! Android app Webview HTML (JS, CSS, etc) Java
  • 6. @sergiandreplace • WebSettings settings=webView.getSettings() • settings. • setJavaScriptEnabled • setGeolocationEnabled • setJavaScriptCanOpenWindowsAutomatically • setBuiltInZoomControls
  • 7. @sergiandreplace • Default behaviour: open links externally (yes, it’s true) • We should intercept the url requests and redirect back to the webview • We need a WebViewClient • WebViewClient handles page events
  • 9. @sergiandreplace • WebViewClient handles page lifecycle and resources loading • .onPageFinished (it’s a trap!) • .onPageStarted • .shouldInterceptRequest (ooooh!) • WebChromeClient Just handles “other” events. More specific to page itself* . • .onProgressChanged (what the…?)
  • 10. @sergiandreplace • Android fragmentation is nothing compared to this • Video full screen is handled by WebChromeClient.onShowCustomView • Android <=2.3.3  view instanceof VideoView • Android >3.0  view instanceof HTML5VideoView . An internal private class (d’oh!) Field proxiedVideoFullScreen = callback.getClass().getDeclaredFields()[0]; proxiedVideoFullScreen.setAccessible(true); Object unproxiedVideoFullScreen=proxiedVideoFullScreen.get(callback); Field mUri= unproxiedVideoFullScreen.getClass().getSuperclass().getDeclaredField("mUri"); mUri.setAccessible(true); path =((Uri)mUri.get(unproxiedVideoFullScreen)).toString();
  • 11. @sergiandreplace • Just put your web on assets and load it • loadUrl("file:///android_asset/... (///!!!) • Java vs. Javascript.Try to be as biased as possible • Do not mix interactive events (touch, drag, etc)
  • 13. @sergiandreplace • We can inject Java objects to the WebView • This object methods can be invoked from JavaScript • Cool, isn’t? So cool that nobody else supports it • Forget DODM! • Sooo…
  • 14. @sergiandreplace • Just use a specific url format and capture it from WebViewClient and Use url to put parameters • This works in all platforms • Uri class is our best friend for parsing urls • Returning values? Add callback function as parameter. All calls are asynchronous • Basically, this is what Cordova does
  • 16. @sergiandreplace • Only one possible solution • loadUrl(“javascript:….”); • End of it
  • 18. @sergiandreplace • Bug http://code.google.com/p/android/issues/detail?id=17535:Url with params not working • Sony (des)Experia • Create a mini-browser to the web team. Don’t relay on Chrome for Android • Abandon Android 3.0. Seriously. • Do a lot of tests • Hardware acceleration:“If your application performs custom drawing, test your application on actual hardware devices with hardware acceleration turned on to find any problems” a.k.a.: Just try