Search code examples
androidandroid-intentlinkedin-api

Unable to open Linkedin profile using intent in android


How to open linkedin profile using intent :

My code :

context.getPackageManager().getPackageInfo(APP_PACKAGE_NAME, 0);
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse("linkedin://profile/" + profileID));
intent.setPackage(APP_PACKAGE_NAME);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

Log:

12-10 19:18:49.363     936-2104/? I/ActivityManager﹕ START u0 {act=android.intent.action.VIEW dat=linkedin://profile/132778900 pkg=com.linkedin.android cmp=com.linkedin.android/.infra.deeplink.DeepLinkHelperActivity} from pid 8392
12-10 19:18:49.373    1223-1377/? E/﹕ no predefined limited group find for com.linkedin.android, add to foreground group
12-10 19:18:49.463    7964-7964/? I/CrashReporter﹕ Starting activity DeepLinkHelperActivity Intent: Intent { act=android.intent.action.VIEW dat=linkedin://profile/132778900 pkg=com.linkedin.android cmp=com.linkedin.android/.infra.deeplink.DeepLinkHelperActivity }
12-10 19:18:49.493    7964-7964/? E/com.linkedin.android.deeplink.helper.LaunchHelper﹕ urlParams was null, indicating a failure to validate the path in getMap()
12-10 19:18:59.523    7964-7996/? D/LinkedInNetwork﹕ Performing request
12-10 19:19:04.573    1619-1666/? I/XiaomiFirewall﹕ firewall pkgName:com.linkedin.android, result:0

Solution

  • Based on the latest documentation from LinkedIn, you should be using the DeepLinkHelper to integrate deep-linking with the official app:

    // Get a reference to an activity to return the user to
    final Activity thisActivity = this;
    
    // A sample member ID value to open
    final String targetID = "abcd1234";
    
    DeepLinkHelper deepLinkHelper = DeepLinkHelper.getInstance();
    
    // Open the target LinkedIn member's profile
    deepLinkHelper.openOtherProfile(thisActivity, targetID, new DeeplinkListener() {
        @Override
        public void onDeepLinkSuccess() {
            // Successfully sent user to LinkedIn app
        }
    
        @Override
        public void onDeepLinkError(LiDeepLinkError error) {
            // Error sending user to LinkedIn app
        }
    });
    

    Or prefer the following to open the profile of the currently authenticated user:

    // Get a reference to an activity to return the user to
    final Activity thisActivity = this;
    
    DeepLinkHelper deepLinkHelper = DeepLinkHelper.getInstance();
    
    // Open the current user's profile
    deepLinkHelper.openCurrentProfile(thisActivity, new DeeplinkListener() {
        @Override
        public void onDeepLinkSuccess() {
            // Successfully sent user to LinkedIn app
        }
    
        @Override
        public void onDeepLinkError(LiDeepLinkError error) {
            // Error sending user to LinkedIn app
        }
    });
    

    Either way, if dive into the implementation of the DeepLinkHelper, you'll see that it ends up constructing the Intent that opens the LinkedIn app like this:

    private void deepLinkToProfile(@NonNull Activity activity, String memberId, @NonNull AccessToken accessToken) {
        Intent i = new Intent("android.intent.action.VIEW");
        Uri.Builder uriBuilder = new Uri.Builder();
        uriBuilder.scheme("linkedin");
        if (CURRENTLY_LOGGED_IN_MEMBER.equals(memberId)) {
            uriBuilder.authority(CURRENTLY_LOGGED_IN_MEMBER);
        } else {
            uriBuilder.authority("profile").appendPath(memberId);
        }
        uriBuilder.appendQueryParameter("accessToken", accessToken.getValue());
        uriBuilder.appendQueryParameter("src", "sdk");
        i.setData(uriBuilder.build());
        Log.i("Url: ", uriBuilder.build().toString());
        activity.startActivityForResult(i, LI_SDK_CROSSLINK_REQUEST_CODE);
    } 
    

    As you can see, amongst other things, it attaches the access token to the Uri as a query parameter with key accessToken. The other query parameter that gets added is src, which (presumably) is just used for statistical purposes and not something functional.

    Now, if you look at this particular line in your error log:

    E/com.linkedin.android.deeplink.helper.LaunchHelper﹕ urlParams was null, indicating a failure to validate the path in getMap()
    

    Note:

    urlParams was null

    That sounds to me like it is expecting one ore more query parameters for the data Uri. I'm inclined to say that that is most likely referring to (at least) the accessToken query parameter that is missing in your own code snippet, yet is part of the SDK flow.

    Hopefully that's a push in the right direction. It might be easiest to just use the LinkedIn SDK - any particular reason you aren't?