【问题标题】:how can i send a skype message from My android app?如何从我的 android 应用程序发送 Skype 消息?
【发布时间】:2013-12-30 17:47:08
【问题描述】:

我试着做一个像调用意图这样的意图

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

它没有用。

【问题讨论】:

    标签: android android-intent skype skype4com


    【解决方案1】:

    官方 Android SDK 以及 Skype URI 的问题是它们不允许共享预定义消息。您可以只打开与用户列表的聊天(或清空以创建新用户)。如果你想明确地与 Skype 共享一些文本,你可以尝试使用带有 Skype 包名的系统 Intents(记得检查是否安装了这个包名,否则 startActivity 调用会导致你的应用程序崩溃):

    val SKYPE_PACKAGE_NAME = "com.skype.raider"
    
    fun shareSkype(context: Context, message: String) {
        if (!isAppInstalled(context, SKYPE_PACKAGE_NAME)) {
            openAppInGooglePlay(context, SKYPE_PACKAGE_NAME)
            return
        }
        val intent = context.packageManager.getLaunchIntentForPackage(SKYPE_PACKAGE_NAME)
        intent.action = Intent.ACTION_SEND
        intent.putExtra(Intent.EXTRA_TEXT, message)
        intent.type = "text/plain"
        context.startActivity(intent)
    }
    
    fun isAppInstalled(context: Context, packageName: String): Boolean {
        val packageManager = context.packageManager
        try {
            packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
        } catch (e: PackageManager.NameNotFoundException) {
            return false
        }
        return true
    }
    

    【讨论】:

      【解决方案2】:

      如果 Skype 或其他 Android 消息传递应用程序没有公开可用的 Intent,则在它们可用之前无法这样做。

      但是,您可以尝试找到 Skype 用来在您的应用程序中调用的代理服务,作为发送消息的一种方式。

      http://developer.skype.com/skype-uris/reference#uriChats

      注意:

      注意事项:

      可选的主题参数仅适用于多人聊天。

      主题参数值中的特殊字符(特别是空格)必须转义。

      Mac OS X:忽略任何主题参数。

      iOS:不支持。

      Android:仅识别初始参与者;不支持多人聊天。

      Android 文档 - http://developer.skype.com/skype-uris/skype-uri-tutorial-android

      /**
       * 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 since we'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;
      }
      

      【讨论】:

      • 不相关的答案!您的代码和链接将打开聊天而不是发送短信!
      • @Choletski 代码和link 最初展示了如何启动任何 Skype URI。由于mySkypeUri 在上面的代码中是模棱两可的,它可能意味着很多动作。在之前的评论中发布的updated Skype URI API reference link 涵盖了各个项目,其中包括:“向个人发送即时消息或建立群组多聊天”。在撰写答案时这是可能的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-13
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多