Last active
August 29, 2015 14:18
-
-
Save GantMan/3089ccbb4dbe704a92da to your computer and use it in GitHub Desktop.
Webview Check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity < Android::App::Activity | |
attr_reader :webview | |
def onCreate(savedInstanceState) | |
super | |
@webview = Android::Webkit::WebView.new(self) | |
settings = @webview.settings | |
settings.savePassword = true | |
settings.saveFormData = true | |
settings.javaScriptEnabled = true | |
settings.supportZoom = false | |
@webview.setWebViewClient(CustomClient.new) | |
# Some site that redirects with a 302 | |
@webview.loadUrl("http://goo.gl/xZsY2h") | |
self.contentView = @webview | |
end | |
end | |
class CustomClient < Android::Webkit::WebViewClient | |
def shouldOverrideUrlLoading(view, url) | |
# Try to handle redirection (301/302) | |
puts "***" * 10 | |
p url | |
# NOTICE: View passed in has a different address in memory | |
p view | |
p view.getContext.webview | |
puts "***" * 10 | |
# I've been told this should work | |
#view.loadUrl(url) | |
# This doesn't work either | |
view.getContext.webview.loadUrl(url) | |
true # when return true, stop natural loading URL from happening | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment