LinkedIn Authentication not working on Fragment in android
Asked Answered
G

2

5

I am creating an app that has the LinkedIn login. I am following this documentation. But when I click on the login button, the app redirected to the LinkedIn app and asking for login. When successful login it redirected to my app. But nothing happens. Nothing happens on onActivityResult also. Below is my code .Login implemented on fragment

 LISessionManager.getInstance(getActivity()).init(getActivity(), buildScope(), new AuthListener() {
            @Override
            public void onAuthSuccess() {
                getLinkedInProfile();
                Toast.makeText(getApplicationContext(), "success" , Toast.LENGTH_LONG).show();
            }
            @Override
            public void onAuthError(LIAuthError error) {
                Toast.makeText(getApplicationContext(), "failed " + error.toString(), Toast.LENGTH_LONG).show();
            }
        }, true);

//

private static Scope buildScope() {
    return Scope.build(Scope.R_BASICPROFILE, Scope.R_EMAILADDRESS);
}

and onActivityResult as follows:

     @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        LISessionManager.getInstance(getActivity()).onActivityResult(getActivity(), requestCode, resultCode, data);
}

Already added hash and package name on LinkedIn developer console. Did I am missing anything? Please help

Gourmont answered 5/9, 2017 at 18:27 Comment(4)
Same thing here also. I am getting the same code worked in activity. But when used in fragment it is no working!!!Myna
Actually I found a solution for @MynaGourmont
Then please write it as an answer. Will be useful for many others like me. @Vinayak BMyna
Please check my answerGourmont
G
5

It is found that the onActivityResult for LinkedIn sdk triggres on the parent activity rather than fragment onActivityResult. So you have to write following code into your parent Activity's onActivityResult for triggering fragment's onActivityResult.

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    yourFragment.onActivityResult(requestCode, resultCode, data);
}
Gourmont answered 11/9, 2017 at 6:23 Comment(0)
I
1

Try Log to ensure whether function is called.

Invidious answered 5/9, 2017 at 18:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.