6

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?

Community
  • 1
  • 1
Noneu
  • 95
  • 1
  • 5

1 Answers1

9

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

Alécio Carvalho
  • 13,481
  • 5
  • 68
  • 74
Jompis
  • 640
  • 1
  • 8
  • 18
  • I knew that there was an easy way to do that ! Thank you very much @Jompis, your post saved me !! – Noneu Oct 10 '11 at 12:48
  • 1
    Would anyone know the class name to only open twitter application? intent.setClassName("com.twitter.android", "com.twitter.android"); Apparently this does not work. – SoH Oct 13 '12 at 19:16
  • 1
    updated the answer, it is now: com.twitter.android.composer.ComposerActivity – Alécio Carvalho Jun 08 '16 at 08:40