Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Callbacks with WebView component?

I am doing authentication with a third-party site that's supposed to redirect back to my app with auth token (OAUTH).

I have the callback working properly if I open the 3rd party site in a separate browser process via

this.startActivity(new Intent(Intent.ACTION_VIEW, uri));

but, if I embed a WebView component in my layout, and open the url in that, the callback does not work. Webview says "You do not have permission to open myapp://callback?token=...." and quickly refreshes to "Web page not available...temporarily down...blah blah"

Any ideas?

like image 805
Saideira Avatar asked Sep 17 '10 17:09

Saideira


People also ask

How do you communicate between WebView and native Android?

2.1 To receive data from webview ,we can create an interface, which will enable webview to connect the native layer and pass data. From native layer, create a class and replicate the following. While configuring web view, we need to set JavaScript interface as above JSBridge class.

Is Android WebView deprecated?

This interface was deprecated in API level 12. This interface is now obsolete.

What is the use of WebViewClient in Android?

If you want to deliver a web application (or just a web page) as a part of a client application, you can do it using WebView . The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout.

How do I enable JavaScript on Android WebView?

This example demonstrate about How to enable webview java script in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


1 Answers

You need to implement a WebViewClient to intercept the custom URI before it is loaded. The Hello, WebView tutorial shows a simple example. Where they have:

private class HelloWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}

You can change "view.loadUrl(url)" to check if the URL is your custom URL and handle it however you want.

like image 116
Ian G. Clifton Avatar answered Oct 09 '22 18:10

Ian G. Clifton