Android Intent to launch appropriate chat client
In my application, I'd like to provide a Chat button. In the context of a specific contact, the user is shown a list of the contact methods available. For example, it might list a Google Talk ID and an AIM ID. The user can click on either ID and it should l开发者_如何学运维aunch the appropriate application that handles the selected chat protocol (if one is installed). Given that I have the protocol and the ID (e.g., PROTOCOL_GOOGLE_TALK and "JohnDoeGtalk"), how can I create an intent that does that?
Thanks.
Have you tried adding @gmail.com in your URI?
The following approach, taken from here, works for me; it opens a new chat with the contact, using the Google Talk app. Using HTC Desire running Froyo. Code:
Uri imUri = new Uri.Builder().scheme("imto").authority("gtalk").appendPath("example@gmail.com").build();
Intent intent = new Intent(Intent.ACTION_SENDTO, imUri);
startActivity(intent);
An ACTION_SENDTO
Intent
with a Uri
whose scheme is imto://...
may work. See this issue and comment #2 for the apparently-valid syntax. Note that I have not tried this, and this issue is from quite some time ago.
精彩评论