Java 如何从Android应用程序启动Skype呼叫?

Java 如何从Android应用程序启动Skype呼叫?,java,android,skype,Java,Android,Skype,我正在尝试从我的Android应用程序启动一个Skype应用程序,传递一个电话号码。到目前为止,多亏了stackoverflow上的其他用户,我成功地启动了skype,但仍然无法传递电话号码。这是我正在使用的代码: Intent sky = new Intent("android.intent.action.CALL_PRIVILEGED"); sky.setClassName("com.skype.raider", "com.skype.raid

我正在尝试从我的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);
发生的事情是skype启动了,但给了我一杯酒,说号码无效,并建议我添加国际前缀。 日志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);
    }

}
事实上,当我转到Skype的视图进行呼叫时,我看到它是由+0组成的 因此,在我看来,我以错误的方式传递了电话号码,或者传递到了错误的活动中……任何帮助都将不胜感激!
同时,我只想说StackOverflow简直就是个摇滚乐。

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

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

请参见以下答案:

杰夫建议使用
skype:
而不是
tel:

在使用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开发者: 还记得在url中添加“?call”

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

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

请参阅此Skype文档链接

首先需要检查skype是否已安装或未使用

使用启动skype uri

如果未安装Skype,则使用重定向至市场


您好,谢谢您的回答。我知道,当然,我已经尝试过向我的客户解释这一点,但遗憾的是,我正在尝试做这件事…如何以编程方式输入Skype登录屏幕的凭据?可能用户未登录应用程序如果回答有帮助,请将其标记为已接受,以便其他人可以使用如果你以不同的方式解决了问题,你可以回答自己的问题并接受它。这个答案很有帮助,但没有包含确切的过程,我应该编写工作代码作为问题的答案还是编辑问题?这非常有效(对我来说)。我需要一种方法来启动Skype呼叫,而不需要用户的任何干预。我尝试过,但它只是打开akype应用程序,没有拨打电话号码。有什么想法吗?如何进行Skype视频呼叫?这非常适合(我)。我需要一种方法来启动Skype呼叫,而无需用户进行任何干预。如何以编程方式输入Skype登录屏幕的凭据?可能用户未登录到应用程序。如何以编程方式输入Skype登录屏幕的凭据?可能用户未登录到应用程序。我感觉没有任何区别thout“?call”部分。此外,“skype:”功能对我来说只适用于现代skype。旧的只会弹出skype拨号屏幕,但不会拨打电话。使用用户名而不是电话使其在所有情况下都能正常工作。使用“skype:”的号码的问题在我尝试从
am start skype:phonenumber
运行时也会发生。
/**
 * 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 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;
}
/**
 * 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;
}