从我的 Android 应用程序启动与 MS Teams Android 应用程序中的用户聊天

问题描述:

我有一个 Android 应用,点击按钮应该会启动 Microsoft Teams Android 应用并打开与预定义用户的聊天.

I have an Android app, where a tap on a button should launch Microsoft Teams Android app and open a chat with a pre-defined user.

是否可以做,如果可以,怎么做?

Is it possible to do and if yes - how?

如果您知道用户在 MS Teams 中注册的电子邮件(例如:username@email.com),您可以使用以下两个选项之一直接打开与他/她的聊天:

If you know user's E-Mail with which he/she is registered in MS Teams (ex: username@email.com), you can directly open chat with him/her using one of two options:

  1. 向用户显示一个选择表,可选择在 MS Teams Android 应用程序或网络浏览器之一中打开聊天:

  1. show user a chooser sheet with a choice to open chat in MS Teams Android app or one of web browsers:

val sendIntent = Intent(Intent.ACTION_VIEW,
    Uri.parse("https://teams.microsoft.com/l/chat/0/0?users=username@email.com"))

if (sendIntent.resolveActivity(packageManager) != null) {
    startActivity(sendIntent)
}

  • 在 MS Teams Android 应用中强制与用户打开聊天.同上,但在 Uri https 中替换为 msteams:

    Uri.parse("msteams://teams.microsoft.com/l/chat/0/0?users=username@email.com")