有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我正在尝试从我的Android应用程序启动一个Skype应用程序,传递一个电话号码。到目前为止,多亏了stackoverflow上的其他用户,我成功地启动了skype,但仍然无法传递电话号码。这是我正在使用的代码:

Intent sky = new Intent("安卓.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("hello安卓 dialing example", "Call failed", e);
    }

}

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


共 (4) 个答案

  1. # 1 楼答案

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

    杰夫建议用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);
            }
    
        }
    
  2. # 2 楼答案

    请参阅此skype文档链接Skype URI tutorial: Android apps

    First need to check skype is installed or not using

    /**
     * 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

    /**
     * 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

    /**
     * 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;
    }
    
  3. # 3 楼答案

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

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

  4. # 4 楼答案

    请参阅Skype开发者:Skype URI tutorial: Android apps 还记得在url中添加“?call”。例如

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

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