从应用程序中以编程方式启动Skype并传递号码 - Android

14

我正在尝试通过我的应用程序启动并将电话号码传递给Skype:

PackageManager packageManager = getPackageManager();
Intent skype = packageManager.getLaunchIntentForPackage("com.skype.raider");
skype.setData(Uri.parse("tel:65465446"));
startActivity(skype);

Skype已启动,但无法捕获号码。


6个回答

37

这段代码对我来说有效,可以启动两个Skype用户之间的通话:

Intent sky = new Intent("android.intent.action.VIEW");
sky.setData(Uri.parse("skype:" + user_name));
startActivity(sky);

要找到这个(和其他)内容,请使用apktool打开Skype APK。查看AndroidManifest.xml,您将看到所有已知的意图过滤器。如果您想触发其中一个意图过滤器,您需要创建一个能够匹配其的意图。这是上面代码所匹配的意图过滤器:

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="skype" />
        </intent-filter>

通过new Intent(),您可以免费获得类别为“android.intent.category.DEFAULT”的内容,因此只需要设置操作和URI。

用于tel: URI的意图过滤器如下所示:

        <intent-filter android:icon="@drawable/skype_blue" android:priority="0">
            <action android:name="android.intent.action.CALL_PRIVILEGED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="tel" />
        </intent-filter>

所以您将动作设置为并为 Intent 提供了一个 tel: URI,"正确的事情"将发生。发生的是,Android找到了正确的提供程序来处理 tel: URI。它可能会获取用户输入,以选择电话应用程序和 Skype 之间的区别。Skype 处理 tel: URI 的优先级为零,即最低。因此,如果已安装电话应用程序,则它很可能会获取 Intent。


随着最新的Skype版本发布,这个答案已经失效了 - 参考下面Martin的答案并包含URI扩展名。 - brandall
2
我试过了,但它只是打开了Skype应用程序,而没有拨打号码。有什么想法吗? - TheGraduateGuy
有人可以帮我解决这个问题吗?http://stackoverflow.com/questions/35353839/how-to-enter-credentials-programmatically-in-skype-app-for-android - Parth Doshi
如何调用?有什么想法吗?它只是启动Skype应用程序。 - Rahul Kushwaha

17

如果您想触发一个视频通话,您需要在Skype URI中添加"?call&video=true"。

Intent skypeVideo = new Intent("android.intent.action.VIEW");
skypeVideo.setData(Uri.parse("skype:" + "<username>" + "?call&video=true"));
startActivity(skypeVideo);

更多关于Skype URI的信息可在以下链接中找到: http://developer.skype.com/skype-uris-program/skype-uri-ref

编辑:

不使用任何意图选择器直接拨打Skype电话:

如果您想要不使用任何意图选择器直接拨打Skype电话,请在您的清单文件中添加以下行...

               <intent-filter
                    android:icon="@drawable/skype"
                    android:priority="0" >
                    <action android:name="android.intent.action.CALL_PRIVILEGED" />

                    <category android:name="android.intent.category.DEFAULT" />

                    <data android:scheme="tel" />
                </intent-filter>
                <intent-filter>
                    <intent-filter
                        android:icon="@drawable/skype"
                        android:priority="0" >
                        <action android:name="android.intent.action.VIEW" />
                        <action android:name="android.intent.action.CALL" />

                        <category android:name="android.intent.category.BROWSABLE" />
                        <category android:name="android.intent.category.DEFAULT" />

                        <data android:scheme="skype" />
                    </intent-filter>


                </intent-filter>

Skype 的最新更新意味着接受的答案不再有效,除非您详细说明 URI 扩展名 - 谢谢。对于文档链接的 +1 也感谢! - brandall
1
更新的API参考链接:https://msdn.microsoft.com/zh-cn/library/office/dn745882.aspx - Abhijit Kurane

4
请使用以下代码适用于Skype版本2:
Intent skype_intent = new Intent("android.intent.action.VIEW");
skype_intent.setClassName("com.skype.raider", "com.skype.raider.Main");
skype_intent.setData(Uri.parse("skype:skypeusername"));
startActivity(skype_intent);

1

使用此代码,您将获取Skype活动的意图而不是呼叫者活动的意图。因此,您必须查找具有用于操作CALL的意图过滤器的活动的意图。但更清楚地说,Skype使用操作 android.intent.action.CALL_PRIVILEGED,因此按此过滤器查找。 仅供信息,呼叫者活动为 cmp=com.skype.raider.contactsync.ContactSkypeOutCallStartActivity。


可以使用CALL,因为Skype无法拨打紧急号码;但是如果您想始终启动Skype,请使用具有指定Activity类的Intent或用户可以选择其他应用程序。 - molnarm
它奏效了!通过这段代码:Intent sky = new Intent("android.intent.action.CALL_PRIVILEGED"); sky.setClassName("com.skype.raider", "com.skype.raider.contactsync.ContactSkypeOutCallStartActivity"); sky.setData(Uri.parse("tel:65465446")); startActivity(sky); - ruben
那只适用于Skype Out。请查看我的答案以获取更完整的解决方案。 - Jeff Allen
@ruben,ContactSkypeOutCallStartActivity的代码是什么? - Rahul Kushwaha

0

我发现上面的代码不起作用...

Intent i = packageManager.getLaunchIntentForPackage("com.skype.raider");
// i.setAction("android.intent.cation.CALL_PRIVILEGED");
// i.setClassName("com.skype.raider", "com.skype.raider.contactsync.ContactSkypeOutCallStartActivity");
// i.setData(Uri.parse("tel:5551234")); 
startActivity(i);

注释掉的代码行要么使其无法正常工作,要么没有任何作用!

按照现有的代码,将调用Skype并到达一个页面,您可以在该页面上选择Skype联系人。如需更多信息,请随时提出。

约翰


0

Skype 2.X的清单与Skype 1.X有很大不同。没有ContactSkypeOutCallStartActivity。新的清单包含代码:

<activity android:name="com.skype.raider.Main" android:launchMode="singleTask"  android:configChanges="keyboardHidden|orientation" android:windowSoftInputMode="adjustResize">
...
  <intent-filter android:icon="@drawable/skype_blue" android:priority="0">
     <action android:name="android.intent.action.CALL_PRIVILEGED" />
     <category android:name="android.intent.category.DEFAULT" />
     <data android:scheme="tel" />
  </intent-filter>
...
</activity>

所以你应该写成:

Intent skype_intent = new Intent("android.intent.action.CALL_PRIVILEGED");
skype_intent.setClassName("com.skype.raider", "com.skype.raider.Main");
skype_intent.setData(Uri.parse("tel:65465446")); 
context.startActivity(skype_intent);

请注意,此方法不允许您使用Skype开始通话/聊天。它仅适用于Skype Out。

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