Search code examples
androidfacebookandroid-intenttwitter

How does twitter/facebook know on which apps tweet/status/images can be shared?


My question is when I want to share a tweet on from twitter app when I press the share button a pop up opens and displays all the apps that on which I can share my tweet. How does twitter app knows which apps to display? This is similar to when an image is opened a pop up comes up and asks for the app we want to view the image in. How does any OS figures out which apps to display.

My guess is that something has to be done with the original application itself. Attached is an image for reference

enter image description here


Solution

  • In the above screenshot Facebook, Twitter, G+ etc are using Intent Filters.

    By defining intent filter you can achieve this. You can register your Android components via intent filters for certain events.If a component does not define one, it can only be called by explicit intents. The key for this registration is that your component registers for the correct action, mime-type and specifies the correct meta-data.

    Eg.

    <activity android:name=".BrowserActivitiy"
      android:label="@string/app_name">
      <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <data android:scheme="http"/>
      </intent-filter>
    </activity>
    

    Above code will register an Activity for the Intent which is triggered when someone wants to open a webpage.

    Source: http://www.vogella.com/tutorials/AndroidIntent/article.html