Skip to content

Instantly share code, notes, and snippets.

@GantMan
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GantMan/3089ccbb4dbe704a92da to your computer and use it in GitHub Desktop.
Save GantMan/3089ccbb4dbe704a92da to your computer and use it in GitHub Desktop.
Webview Check
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