I'm implementing share functions on my Android application. I already have intergrated an intent chooser to share a text type message. Now, I'd like to create two shortcuts : one to access to the user's Facebook post page, another to access to his twitter post page. (as the chooser do)
I found this helpful topic : launch facebook app from other app and tried to find the right word (fb://word) using the ADB shell command but I can't figure out ("publish", "publishing", "post", "share", "sharing" don't work).
Then I tried to catch the created intent (via the Log) on the intent chooser when I was clicking on Facebook or Twitter. I found :
"Starting: Intent { act=android.intent.action.SEND typ=text/plain flg=0x3000000 cmp=com.twitter.android/.PostActivity (has extras) } from pid 17575" for Facebook, and
"Starting: Intent { act=android.intent.action.SEND typ=text/plain flg=0x3000000 cmp=com.facebook.katana/.ShareLinkActivity (has extras) } from pid 17575" for Twitter.
I created those intents with the following codes (on the buttons' onClick()
methods):
Intent fbIntent = new Intent(Intent.ACTION_SEND);
fbIntent.setType("text/plain");
fbIntent.setFlags(0x3000000);
fbIntent.setComponent(new ComponentName("com.facebook.katana", ".ShareLinkActivity"));
fbIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text));
startActivity(fbIntent);
I also tried this way:
Intent twitterIntent = new Intent(Intent.ACTION_VIEW);
twitterIntent.setAction("android.intent.action.SEND");
twitterIntent.setFlags(0x3000000);
twitterIntent.setType("text/plain");
twitterIntent.setComponent(new ComponentName("com.twitter.android", ".PostActivity"));
twitterIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text));
startActivity(twitterIntent);
But even if the logs look the same nothing happens.
Any idea?
I think you should use setClassName instead of setComponent.
intent.setClassName("com.facebook.katana", "com.facebook.katana.ShareLinkActivity");
intent.setClassName("com.twitter.android", "com.twitter.android.composer.ComposerActivity");
Note: Recent Twitter versions are using 'com.twitter.android.composer.ComposerActivity' (instead of 'com.twitter.android.PostActivity')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With