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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10132556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 23:43:36  来源:igfitidea点击:

How to start a Skype call from an Android app?

javaandroidskype

提问by Daniele

I'm trying to start a Skype intent from my Android App, passing a phone number. So far, thanks to other people who ad similiar needs here on stackoverflow, I've managed to start skype, but still I can't pass the phone number. This is the code I'm using:

我正在尝试从我的 Android 应用程序启动 Skype 意图,并传递一个电话号码。到目前为止,感谢在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);

What's happening is that skype starts, but gives me a toast saying that the number is not valid, and suggests me to add the international prefix. The Log.d gives me tel:+39........ (the number works, I'm using it also for

发生的事情是 Skype 启动,但给我一个敬酒说该号码无效,并建议我添加国际前缀。Log.d 给了我电话:+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);
    }

}

In fact, when I go to the Skype's view for calling, I see it's been composed +0 So what it seems to me is that I'm passing the phone number in the wrong way, or to the wrong Activity....any help would be very appreciated! In the meantime, I just want to say that StackOverflow simply rocks.

事实上,当我转到 Skype 的视图进行呼叫时,我看到它已被组合 +0 所以在我看来,我以错误的方式传递了电话号码,或者传递给了错误的 Activity....any帮助将不胜感激!与此同时,我只想说 StackOverflow 简直太棒了。

回答by marmor

See this answer: https://stackoverflow.com/a/8844526/819355

看到这个答案:https: //stackoverflow.com/a/8844526/819355

Jeff suggests using a skype:<user name>instead of tel:<phone number>

杰夫建议使用skype:<user name>代替tel:<phone number>

After some studing of the skype apk with apktool, as suggested in that answer, I came up with this code, for me it's working:

在使用 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);
        }

    }

回答by HiMobilet

Refer to Skype developer: Skype URI tutorial: Android appsAlso remember to add "?call" in your url. E.g

请参阅 Skype 开发人员:Skype URI 教程:Android 应用程序还记得在您的 url 中添加“?call”。例如

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

Without it, Skype may not dial the number.

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

回答by Snicolas

You should not include a specific class when calling an external app. Let the user decide of the application he/she wants to use. That's the way android has been designed and it's a better solution than obliging people to use a soft (moreover quite a slow, closed and inconvenient app to my mind).

调用外部应用程序时不应包含特定类。让用户决定他/她想要使用的应用程序。这就是 android 的设计方式,它是比强迫人们使用软件更好的解决方案(而且在我看来,这是一个非常缓慢、封闭且不方便的应用程序)。

In other words, just use the Uri, that's the job of skype of declaring its ability to capture such intents.

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

回答by Upendra Shah

Refer this skype doc link Skype URI tutorial: Android apps

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

First need to check skype is installed or not using

首先需要检查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);
}

initiate skype uri using

启动 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;
}

if Skype is not installed then redirect to market place using

如果未安装 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;
}