【问题标题】:Start Google Hangout from Intent in New Hangouts Android app在新的 Hangouts Android 应用中从 Intent 启动 Google Hangout
【发布时间】:2013-05-10 20:41:11
【问题描述】:

这里之前有关于从 Android 上的 Intent 发起 Google Hangout 的讨论: start google hangouts in android

How can I start a Google Hangout in Android with an Intent?

结论是这是不可能的。这是此处要求的增强功能: https://code.google.com/p/google-plus-platform/issues/detail?id=385

不过,昨天 Google 发布了一款新的环聊应用,其中包含一组新的意图。现在可以通过 Intent 发起环聊了吗?

我在action=android.intent.action.VIEWdata=content://plus.google.com/hangouts 方面取得了部分成功。

但是,我想传递我要呼叫的人的姓名或 ID——收件人姓名。我想不通。

新的基于浏览器的环聊应用使用如下 URL 开始环聊:

https://plus.google.com/hangouts/_/CONVERSATION/[26-character ID]?hl=en_US&hscid=[19-digit ID]&hpe=[14-character value]&hpn=[Google+ Name of Recipient]&hnc=0&hs=41.

我假设并非所有这些参数都是启动环聊所必需的,但我无法破译如何在意图中传递收件人姓名。

有什么想法吗? 谢谢。

【问题讨论】:

    标签: android android-intent hangout


    【解决方案1】:

    嘿,我想你试试这个。

    Intent sky = new Intent("android.intent.action.VIEW", Uri.parse("https://talkgadget.google.com/hangouts/extras/talk.google.com/myhangout"));
    startActivity(sky);
    

    你只需要提供环聊的网址,但不幸的是谷歌暂停了命名的环聊,所以这个网址每次都会改变。

    【讨论】:

    • 不幸的是,这并没有达到我想要的效果。我知道如何启动应用程序,但我需要能够自动呼叫收件人。换句话说,我需要能够通过意图传递接收者。
    • 另外,为了清楚起见,我说的是昨天 2013 年 5 月 15 日刚刚发布的全新环聊应用。这与旧的 Google+ 环聊意图不同,后者绝对不允许将接收者传递给意图。
    • 您找到了实现此目的的方法吗?
    • 我认为这是一个进步。它确实允许您加入环聊,但您仍然需要按一个按钮。可能有一个参数说“不要等待按下按钮”。你可能会浪费很多时间来开始一个有 5 或 6 个人试图点击屏幕的会话!
    【解决方案2】:

    所以我不知道这是否对其他人有帮助,因为我主要是想使用 tasker 来触发意图。如果您进入 Google+ > 设置 > 通讯录,您可以选中“保持通讯录保持最新”,它会在您点击 Android 中的用户时出现的卡片中添加一些新操作。然后您可以使用Intent Intercept 来读取通过的值。这是我得到的:

    ACTION: android.intent.action.VIEW
    DATA: content://com.android.contacts/data/5555
    TYPE: vnd.android.cursor.item/vnd.googleplus.profile.comm
    
    FLAGS:
    FLAG_ACTIVITY_FORWARD_RESULT
    FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
    FLAG_ACTIVITY_PREVIOUS_IS_TOP
    
    1 ACTIVITIES MATCH THIS INTENT:
    Hangouts (com.google.android.talk - com.google.android.apps.babel.phone.BabelProfileActionActivity)
    

    我能够使用前三个值正确打开与该联系人的对话。显然,您的数据字段中的数字会根据联系人而变化。你可以使用 Intent Intercept 这个技巧,或者如果你有 root 权限,你可以使用类似SQLite Debugger 的东西来破解联系人数据库中的数据表,并找到 MIMETYPE_ID = 16 和 DATA4 = 10 的行。你会也必须找出你的 RAW_CONTACT_ID 是什么。祝你好运!

    【讨论】:

    • 您能解释一下如何使用查询获取“数据”值的数量吗?
    【解决方案3】:

    环聊可以处理通用的分享意图。

    代码如下:

            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.setType("text/plain");
            sendIntent.putExtra(Intent.EXTRA_TEXT, "text to be shared");
    
            activity.startActivity(sendIntent);
    

    【讨论】:

    • 这正是 Android 的工作方式,Intent 让用户选择打开哪个应用程序。
    【解决方案4】:

    这样试试

    以下方法用于将文本分享到视频群聊

    /**
     * Initiate the actions encoded in the specified URI.
     */
    public void initiateHangOutUri(Context myContext, String textToShare) {
    
      // Make sure Android client is installed.
      if (!isHangOutClientInstalled(myContext)) {
        goToMarket(myContext);
        return;
      }
    
      Intent sendIntent = new Intent();
      sendIntent.setAction(Intent.ACTION_SEND);
      sendIntent.putExtra(Intent.EXTRA_TEXT, textToShare);
      sendIntent.setType("text/plain");
      sendIntent.setPackage("com.google.android.talk");
      context.startActivity(sendIntent);
    
      return;
    }
    

    使用以下方法检查此设备上安装的 HangOut

    /**
     * Determine whether the HangOut for Android client is installed on this device.
     **/
    public boolean isHangOutClientInstalled(Context myContext) {
      final PackageManager packageManager = context.getPackageManager();
        Intent intent = packageManager.getLaunchIntentForPackage("com.google.android.talk");
        if (intent == null) {
            return false;
        }
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    }
    

    如果未安装 HangOut,以下方法使用 goto playstore

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

    【讨论】:

      【解决方案5】:

      简单的解决方案是,查询 ContactContract.Data 的 _id 和 MIME 类型。

      ContentResolver resolver = context.getContentResolver();  
      cursor = resolver.query(
                  ContactsContract.Data.CONTENT_URI,
                  null, null, null,
                  ContactsContract.Contacts.DISPLAY_NAME);
      
      //Now read data from cursor like 
      
      while (cursor.moveToNext()) {
            long _id = cursor.getLong(cursor.getColumnIndex(ContactsContract.Data._ID));
            String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
            String mimeType = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.MIMETYPE));
      
            Log.d("Data", _id+ " "+ displayName + " " + mimeType );
      
      }
      

      输出将如下所示

      12561 艾伦 vnd.android.cursor.item/vnd.googleplus.profile.comm

      12562 艾伦 vnd.android.cursor.item/vnd.googleplus.profile.comm

      12564 艾伦 vnd.android.cursor.item/vnd.googleplus.profile

      现在只将那些 MIME 类型为 vnd.android.cursor.item/vnd.googleplus.profile.comm 的 _Id 保存在 DB 或其他地方

      然后你以这种方式向这些联系人发起环聊通话/消息

      Intent intent = new Intent();
                  intent.setAction(Intent.ACTION_VIEW);
      
      // the _ids you save goes here at the end of /data/12562     
           intent.setDataAndType(Uri.parse("content://com.android.contacts/data/_id"),
                          "vnd.android.cursor.item/vnd.googleplus.profile.comm");
                  intent.setPackage("com.google.android.talk");
      
      startActivity(intent);
      

      要使上述代码正常工作,您必须在 Google+ 应用 > 设置 > 通讯录中选中“使联系人保持最新状态”。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-14
        • 2011-02-09
        相关资源
        最近更新 更多