Intent to open twitter client on Android

Many Android developers ask how to start the default twitter client from their application. Which Intent should you use?

It is often advised to send an Intent with ACTION_SEND. However, many programs will fire up: Gmail, SMS send, dropbox, twitter clients, MMS Send, flickr send, etc. This is too broad.

On the other hand, some people advise to filter on the MIME type application/twitter. But this is too restrictive: very few clients will recognize this unofficial/non-standardized MIME type (twidroid is among them, but HTC default client is not).

Eventually, I came up with the following solution: list all applications that reply to ACTION_SEND and filter on known package names.

Hope this helps!

  • http://twitter.com/cristiprodan Cristi Prodan

    Pretty cool! Thanks for sharing. 

    partager sur...

     

  • http://twitter.com/cristiprodan Cristi Prodan

    Pretty cool! Thanks for sharing. 

    partager sur...

     

  • Kyle Clegg

    Been looking for this exact example.  I’m guessing we just add « com.facebook.katana » to put facebook in there too?  Awesome!

    partager sur...

     

    • http://regis.decamps.info/ Régis

      Yes, exactly. 

      partager sur...

       

  • Kyle Clegg

    Can you help me understand how to adapt this to display all the possible twitter clients on the phone and let them pick which to share from?

    partager sur...

     

    • Kyle Clegg

      oops. thought i was updating a prof pic. guess I need to learn french.

      partager sur...

       

      • http://regis.decamps.info/ Régis

        Nice to see you anyway. Is disqus dislayed in French to you, as well?

        partager sur...

         

    • http://regis.decamps.info/ Régis

      You can create a dialog that contains a lis with items from ‘list’ (maybe using labelRes) and a onClickListener that starts the associated activity.

      partager sur...

       

  • Letroll

    thank you for the tips

    partager sur...

     

  • Pingback: Android – How to filter specific apps for ACTION_SEND intent | PHP Developer Resource

  • Pingback: Intent to specific application without knowing its package name : Android Community - For Application Development

  • http://enginyapici.com/ Engin Yapici

    Thanks for the great sample code. I am trying to add extra text with this code:

    facebookIntent.putExtra(android.content.Intent.EXTRA_TEXT, « www.example.com »);

    but it doesn’t work. Facebook app fires up but there is no text. Do you have any suggestions?

    Thanks!

    partager sur...