It really depends on how you want the interaction to work. You can:
- Use the API (helped by a library such as twitter4j as suggested by Heiko Rupp) or
- Find a way to integrate with the Twitter application, although there is no published protocol for this, as far as I know. It’s also not a good idea, because many people use other applications like Twidroyd, TweetDeck etc., but it will definitely be cool or
- If you do not expect the user to do this very often, you can simply open
http://twitter.com/?status=<what-to-tweet> with a simple intention.
Method 3 can be easily described here:
Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("http://twitter.com/?status=" + Uri.encode(message))); startActivity(i);
You can also combine 2 and 3. You can try several well-known applications (official Twitter, TweetDeck, ...), and if all of them fail (because they are missing or because they have been updated and the protocol), you resort to opening a browser.
Also note that it is possible that method 3 may actually launch the application instead of the browser (or at least give the user a choice between them) if the application processes the correct intentions.
Another thing worth mentioning is that it’s very possible that you won’t be able to integrate with any Twitter apps. What I said here is purely hypothetical; I have no idea if these applications support such integration. You should consult each application and see if they reveal some intentions that you could use. If they do not, you can still hack a little, and you can find them, but it will be unreliable, because they are likely to break after several updates.
source share