Unable to open Linkedin profile using intent in android
Asked Answered
I

6

6

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
Inmesh answered 10/12, 2015 at 14:2 Comment(5)
When you say 'Open linked in profile', where and how exactly are you opening it?Allottee
method is in another class in which I write code open linkedin profile and I am calling that method on clickInmesh
I'm not exactly sure but are you trying to pass a url along with the intent?Allottee
means? I am not getting what are you sayingInmesh
I have posted whatever I am doing.Inmesh
O
3

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?

Oddfellow answered 11/12, 2015 at 8:25 Comment(1)
So now you have a different problem? Looks like you may have to go through an authorisation flow first (in particular, read the bits down the bottom). Could you also please update your question with what you currently have, or start a new question if your code has fundamentally changed?Oddfellow
B
6
public void openLinkedInPage(String linkedId) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("linkedin://add/%@" + linkedId));
        final PackageManager packageManager = getContext().getPackageManager();
        final List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        if (list.isEmpty()) {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.linkedin.com/profile/view?id=" + linkedId));
        }
        startActivity(intent);
    }
Brave answered 8/5, 2017 at 8:25 Comment(0)
O
3

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?

Oddfellow answered 11/12, 2015 at 8:25 Comment(1)
So now you have a different problem? Looks like you may have to go through an authorisation flow first (in particular, read the bits down the bottom). Could you also please update your question with what you currently have, or start a new question if your code has fundamentally changed?Oddfellow
C
0
Uri.parse("linkedin://you"));
 final PackageManager packageManager = getContext().getPackageManager();
final List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.isEmpty()) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.linkedin.com/profile/view?id=you"));
}
startActivity(intent);
Couchant answered 10/12, 2015 at 19:10 Comment(0)
P
0
const string PACKAGE = "com.linkedin.android";
Intent intent = new Intent(Intent.ActionView, Uri.Parse("https://www.linkedin.com/in/danielroberts0"));
if(isPackageInstalled(Forms.Context, PACKAGE)) {
    intent.SetPackage(PACKAGE);
}
Forms.Context.StartActivity(intent);

None of the solutions provided what I needed - opening a users profile page in the app. by default or website otherwise.

Ref: Check if application is installed - Android

Playwriting answered 24/3, 2016 at 10:48 Comment(0)
O
0

Try this, it will open LinkedIn Profile in app, or open in browser if LinkedIn app is not Installed (works as of Nov 2018, with latest Version LinkedIn App), no need to use DeepLinkHelper

        String profile_url = "https://www.linkedin.com/in/syedfaisal33";
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(profile_url));
            intent.setPackage("com.linkedin.android");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } catch (Exception e) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(profile_url)));
        }
Origin answered 1/11, 2018 at 9:31 Comment(1)
and if you want to choose between LinkedIn app and browser, use this code instead of the 3rd line, Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("linkedin://syedfaisal33"));Origin
S
0
fun getOpenLinkedin(context: Context, url: String) {
    val linkedinIntent = Intent(Intent.ACTION_VIEW)
    linkedinIntent.setClassName("com.linkedin.android", "com.linkedin.android.profile.ViewProfileActivity")
    linkedinIntent.putExtra("memberId", "profile")
    linkedinIntent.setPackage("com.linkedin.android")
    try {
        context.startActivity(linkedinIntent)
    } catch (e: ActivityNotFoundException) {
        context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
    }
}
Sahaptin answered 21/8, 2019 at 6:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.