简体   繁体   English

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

[英]How to start a Skype call from an Android app?

I'm trying to start a Skype intent from my Android App, passing a phone number.我正在尝试从我的 Android 应用程序启动 Skype 意图,并传递一个电话号码。 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.到目前为止,感谢在stackoverflow上有类似需求的其他人,我已经设法启动了Skype,但仍然无法传递电话号码。 This is the code I'm using:这是我正在使用的代码:

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.发生的事情是 Skype 启动,但给了我一个敬酒说该号码无效,并建议我添加国际前缀。 The Log.d gives me tel:+39........ (the number works, I'm using it also for 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!事实上,当我转到 Skype 的视图进行呼叫时,我看到它已被组合 +0 所以在我看来,我以错误的方式传递了电话号码,或者传递给了错误的 Activity....any帮助将不胜感激! In the meantime, I just want to say that StackOverflow simply rocks.与此同时,我只想说 StackOverflow 简直太棒了。

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> Jeff 建议使用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);
        }

    }

Refer to Skype developer: Skype URI tutorial: Android apps Also remember to add "?call" in your url.请参阅 Skype 开发人员: Skype URI 教程:Android 应用程序还记得在您的 url 中添加“?call”。 Eg例如

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

Without it, Skype may not dial the number.没有它,Skype 可能无法拨打该号码。

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 声明其捕获此类意图的能力的工作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM