LinkedIn authentication does not work with fragment in android

I am creating an application called LinkedIn. I follow this documentation. But when I press the login button, the application is redirected to the LinkedIn application and requests a login. Upon successful login, it is redirected to my application. But nothing happens. Nothing happens on onActivityResult . Below is my code. Login implemented in 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); } 

The hash and package name has already been added to the LinkedIn Developer Console. Am I missing something? Please, help

+5
source share
2 answers

Found onActivityResult triggers for LinkedIn sdk for parent activity, not onActivityResult fragment. Therefore, you must write the following code in your onActivityResult parent activity to trigger the onActivityResult .

  @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); yourFragment.onActivityResult(requestCode, resultCode, data); } 
+5
source

Try the log to ensure that the function will be called.

+1
source

Source: https://habr.com/ru/post/1271545/


All Articles