产品增加了一个需求:根据Skype邀请会话链接,跳转到Skype的会话页面。官方未给出相关的解决方案,根据搜索到的资料最后实现了该功能。记录一下摸索的过程:
方案一:根据包名直接跳转(微软官方给的方案)
/**
* Initiate the actions encoded in the specified URI.
*/
public void initiateSkypeUri(Context myContext, String mySkypeUri) {
// Make sure the Skype for Android client is installed.
if (!isSkypeClientInstalled(myContext)) {
goToMarket(myContext);
return;
}
// Create the Intent from our Skype URI.
Uri skypeUri = Uri.parse(mySkypeUri);
Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
// Restrict the Intent to being handled by the Skype for Android client only.
myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Initiate the Intent. It should never fail because you've already established the
// presence of its handler (although there is an extremely minute window where that
// handler can go away).
myContext.startActivity(myIntent);
return;
}
官方给的方案,测试未能实现。我下载的apk,包名其实是”com.skype.rover",改为实际包名也失败。
方案二:根据tel格式的intent跳转
Intent intent = new Intent("android.intent.action.CALL_PRIVILEGED");
intent.setClassName("com.skype.raider", "com.skype.raider.Main");
intent.setData(Uri.parse("tel:" + phone));
startActivity(intent);
这种方案也失败!
方案三:根据LaunchIntentForPackage
Intent intent = getPackageManager().getLaunchIntentForPackage("com.skype.rover");
if (intent == null) {
intent = getPackageManager().getLaunchIntentForPackage("com.skype.raider");
}
intent.setData(Uri.parse("ms-sfb://chat?id=live:.cid.2836abbxxzd54346"));
startActivity(intent);
此方案只能启动Skype,并不能进入聊天页面
方案四:skype:// 这个scheme来启动Skype
点击Skype邀请链接,会出现加入会话的按钮,拦截此时的url,会得到启动的scheme及详细参数,根据此scheme就能成功跳转到对应的聊天页面
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("scheme=skype")) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("skype://live:.cid.45fea242a00032e5?chat&correlationId=b4b43d94-9836-4fae-a28c-5d5a2de87320&utm_source=buddy&utm_content=yX4Y9UC4444B&origin=launcher#Intent;scheme=skype;S.browser_fallback_url=https%3A%2F%2Fgo.skype.com%2Fspaces.getskype;end;"));
startActivity(intent);
} else {
view.loadUrl(url);
}
return true;
}
这里的Uri是修改过的,原始的url是以intent://开头的,需要改成skype。这样就完成了跳转到Skype聊天页面的功能。(这里Skype账号是固定的,也可以截取url中“intent://"后的内容)。
参考链接:
Skype URI tutorial - Android apps | Microsoft Docs
Android Skype Intent - Stack Overflow
Android开发中常用的Intent跳转_PLS的专栏-程序员宅基地 - 程序员宅基地
Html a标签实现点击调用mail,skype,whatsapp,qq等应用进行聊天,拨号,发送邮件-Web前端-萝卜网络博客