Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Oren Tuchin
Oren Tuchin
28,529 Points

Has anyone successfully completed a LInkedIn Oauth2 API Integration via Native Android App's webview?

I have the basics down of setting up the webview to make the initial request, but do not know how to block the redirect using shouldOverrideUrlLoading, and bring everything back into the Activity, while also retrieving the token and user profile. My xml is just a full screen webview. I'm not sure if anything else is needed since I want to redirect to a different activity ("ProfilePage"). I have tried using the following within shouldOverrideUrlLoading:

Intent intent = new Intent(X, ProfilePage.class); startActivity(intent);

but get an error when I try using Context or an Activity for X.

Any code help would be appreciated. Note that Linkedin requires a redirect URL that begins with "https://" so redirecting back into the app from them is not possible. I have tried using the following to get to successfully get to the first step in the authorization process (note that google.com is just a generic placeholder for the redirect URL since I don't actually intend to go there):

public class LinkedInSignIn extends Activity {

private WebView wv1;

protected void onCreate(Bundle savedInstanceState) {

    wv1 = (WebView) findViewById(R.id.webview);
    wv1.setWebViewClient(new MyBrowser());

private class MyBrowser extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return true;