Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcuts to Facebook and Twitter apps post pages

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?

like image 632
Noneu Avatar asked Oct 06 '11 15:10

Noneu


Video Answer


1 Answers

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')

like image 187
Jompis Avatar answered Oct 25 '22 10:10

Jompis