如何使用intent打开linkedin配置文件:
我的代码:
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);
日志:
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
答案 0 :(得分:3)
根据最新的documentation from LinkedIn,您应该使用DeepLinkHelper
将深层链接与官方应用集成:
// 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
}
});
或者更喜欢以下内容来打开当前经过身份验证的用户的个人资料:
// 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
}
});
无论哪种方式,如果潜入implementation of the DeepLinkHelper
,您会看到它最终会构建Intent
,以便像这样打开LinkedIn应用:
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);
}
正如您所看到的,除其他外,它将访问令牌作为带有键Uri
的查询参数附加到accessToken
。添加的另一个查询参数是src
,它(可能)仅用于统计目的而不是功能性的。
现在,如果你在错误日志中查看这一特定行:
E/com.linkedin.android.deeplink.helper.LaunchHelper﹕ urlParams was null, indicating a failure to validate the path in getMap()
注意:
urlParams为空
这听起来像是期待数据Uri
的一个或多个查询参数。我倾向于说这很可能是指(至少)您自己的代码段中缺少的accessToken
查询参数,但它是SDK流程的一部分。
希望这是朝着正确方向发展的方向。最简单的方法就是使用LinkedIn SDK - 你有什么特别的原因吗?
答案 1 :(得分:1)
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)))
}
}
答案 2 :(得分: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);
答案 3 :(得分: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);
所有解决方案都没有提供我所需的内容 - 在应用中打开用户个人资料页面。默认情况下或其他网站。
答案 4 :(得分:0)
尝试此操作,它将在应用程序中打开LinkedIn个人资料,如果未安装LinkedIn应用程序(自2018年11月起运行,使用最新版本的LinkedIn App),则在浏览器中打开,无需使用 DSLContext dsl = DSL.using("jdbc:sqlite::memory:");
DeepLinkHelper