I have been trying to receive a Tweet URL or Tweet ID in my android application by sharing a Tweet from Twitter and choosing my app from the chooser.
I have setup an intent filter which successfully makes my app available when sharing a Tweet.
AndroidManifest.xml
<intent-filter>
<data android:host="twitter.com"
android:scheme="http" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.SEND" />
</intent-filter>
Sharing the Tweet results in my activity getting called, but the Intent doesn't seem to bear the properties of the Intent Filter which made my app available to Twitter's Share Chooser.
I am attempting to capture it inside onResume as follows:
@Override
public void onResume() {
super.onResume();
Intent mIntent = getIntent();
String action = mIntent.getAction();
String type = mIntent.getType();p
Bundle mBundle = mIntent.getExtras();
Uri data = mIntent.getData();
Set<String> mCategories = mIntent.getCategories();
if (mCategories != null) {
for (String cat : mCategories) {
Log.d(TAG + "Intent Category: ", cat);
}
}
try {
URL url = new URL(data.getScheme(), data.getHost(), data.getPath());
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG,"Error getting intent from Twitter");
}
}
}
There is only one category inside mIntent, which is android.intent.category.LAUNCHER.
and the action is android.intent.action.MAIN
mIntent.getExtras() and mIntent.getData() return null, and I am unable to build a url.
I am confused, as it is the addition of the filter shown from my first code stanza, in the Manifest, which results in my app becoming available to Twitter's share chooser, yet that intent seems to be ignored.
Am I setting up my filter incorrectly, or is there something else that I might have missed?
EDIT
Do I, perhaps, need to setup my activity to setup multiple intents?
To try and do that, I've setup quite a variety of different intent filters, but none of them ever seem to be capturing any intents (other than the MAIN / LAUNCHER intent, which always gets called).
I also tried to add workflows for onActivityResult, but this seems redundant as I've always used that method for handling intents were sent from my own app.
UPDATE Hadn't had time to finish working on this, but I will be looking at it again shortly.