如何从Android应用程序开始Skype通话?

7
我正在尝试从我的Android应用程序启动Skype intent,传递一个电话号码。到目前为止,感谢其他在stackoverflow上有类似需求的人,我已经成功启动了Skype,但是我仍然无法传递电话号码。这是我使用的代码:
Intent sky = new Intent("android.intent.action.CALL_PRIVILEGED");
        sky.setClassName("com.skype.raider",
                "com.skype.raider.Main");
        sky.setData(Uri.parse("tel:" + number));
        Log.d("UTILS", "tel:" + number);
        ctx.startActivity(sky);

发生的情况是Skype启动,但会弹出一条消息提示该号码无效,并建议我添加国际前缀。Log.d给出的是tel:+39........(该号码有效,我也在使用它)。

public static void call(String number, Context ctx) {
    try {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:" + number));
        ctx.startActivity(callIntent);
    } catch (ActivityNotFoundException e) {
        Log.e("helloandroid dialing example", "Call failed", e);
    }

}

实际上,当我进入Skype的拨打界面时,我发现它已经被组合成+0。所以我觉得我可能是以错误的方式或者发送到了错误的活动中传递了电话号码...任何帮助都将不胜感激!与此同时,我想说StackOverflow真的很棒。

这个完美地运作(对我来说)。我需要一种方法来启动Skype通话,而不需要用户进行任何干预。 - user462990
如何通过编程方式输入Skype登录屏幕的凭据?用户可能没有登录该应用程序。 - Parth Doshi
4个回答

17
请参考这个答案:https://dev59.com/S2w15IYBdhLWcg3wv-fa#8844526 Jeff建议使用skype:<user name>而不是tel:<phone number> 根据那个答案中的建议,我使用apktool对Skype apk进行了一些研究,并得出了下面的代码,对我来说它已经可以工作了:
public static void skype(String number, Context ctx) {
        try {
            //Intent sky = new Intent("android.intent.action.CALL_PRIVILEGED");
            //the above line tries to create an intent for which the skype app doesn't supply public api

                Intent sky = new Intent("android.intent.action.VIEW");
            sky.setData(Uri.parse("skype:" + number));
            Log.d("UTILS", "tel:" + number);
            ctx.startActivity(sky);
        } catch (ActivityNotFoundException e) {
            Log.e("SKYPE CALL", "Skype failed", e);
        }

    }

我试过了,但它只是打开了 Skype 应用程序,而没有拨打号码。有什么想法吗? - TheGraduateGuy
如何进行 Skype 视频通话? - Sara
可以做同样的事情,但是是用于聊天吗?此外,可以使用电话号码吗? - android developer
@androiddeveloper 如果在Skype应用程序中可以正常工作,那么它可能可以作为意图使用。尝试使用https://play.google.com/store/apps/details?id=com.zmarties.detective查看Skype的清单文件,并检查它们支持的公共意图。 - marmor
@marmor,我最终找到了答案,但还是感谢你的帮助。这是结果链接:https://dev59.com/fJXfa4cB1Zd3GeqPYwa3 。不知道为什么我的问题会被踩得这么惨。我甚至自己回答了很多信息。 - android developer
显示剩余3条评论

7

请参考Skype开发者文档:Skype URI教程:Android应用 同时,请在您的URL中添加“?call”。例如:

intent.setData(Uri.parse("skype:" + phoneNumber + "?call"));

没有它,Skype可能无法拨打电话号码。

如何以编程方式输入Skype登录屏幕的凭据?用户可能没有登录该应用程序。 - Parth Doshi
我感觉没有 "?call" 部分也没什么区别。而且,"skype:" 这个东西只在现代版的 Skype 上有效。旧版本只会弹出 Skype 拨号屏幕,但不会拨打电话。使用用户名而不是电话号码可以让它在所有情况下都能正常工作。即使尝试从 am start skype:phonenumber 运行时,使用 "skype:" 的数字也会给我带来问题。 - m3nda

4

在调用外部应用时,不应包含特定类。让用户决定他/她想要使用的应用程序。这是安卓设计的方式,比强制使用一个软件(我认为此软件相当缓慢、封闭和不便)更好的解决方案。

换句话说,只需使用Uri,这就是Skype声明其捕获此类意图的工作。


1
嗨,谢谢你的回答。我知道,我已经试图向我的客户解释这个问题,但是很遗憾,我现在还在尝试着去做这件事情... - Daniele
如何以编程方式输入Skype登录屏幕的凭据?用户可能没有登录该应用程序。 - Parth Doshi

0

请参考此 Skype 文档链接 Skype URI 教程:Android 应用程序

首先需要使用以下代码检查 Skype 是否已安装:

/**
 * Determine whether the Skype for Android client is installed on this device.
 */
public boolean isSkypeClientInstalled(Context myContext) {
  PackageManager myPackageMgr = myContext.getPackageManager();
  try {
    myPackageMgr.getPackageInfo("com.skype.raider", PackageManager.GET_ACTIVITIES);
  }
  catch (PackageManager.NameNotFoundException e) {
    return (false);
  }
  return (true);
}

使用以下代码启动 Skype URI
/**
 * 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;
}

如果Skype未安装,则使用市场重定向。
/**
 * Install the Skype client through the market: URI scheme.
 */
public void goToMarket(Context myContext) {
  Uri marketUri = Uri.parse("market://details?id=com.skype.raider");
  Intent myIntent = new Intent(Intent.ACTION_VIEW, marketUri);
  myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  myContext.startActivity(myIntent);

  return;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接