2
  Intent i = new Intent(Intent.ACTION_SEND);    
  i.setType("text/html");  
  String str = et.getText().toString(); 
  i.putExtra(android.content.Intent.EXTRA_TEXT,str);  
  startActivity(Intent.createChooser(i,"Share using"));

I can't open Facebook and Twitter with this code in Android but other applications like Gmail and Skype are opened successfully. Why's that? And how do I open Facebook and Twitter?

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
Shail Modi
  • 27
  • 4

2 Answers2

5

Can you try this code:

private void facebooktaPaylas() {
    try {
        String facebookUri = "http://m.facebook.com/sharer.php?u=";
        String marketUri = "your sharing text");
        Intent shareOnFacebookIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(facebookUri + marketUri));
        startActivity(shareOnFacebookIntent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private void twitterdaPaylas() {
    try {
        String facebookUri = "http://mobile.twitter.com/home?status=";
        String marketUri = "your sharing text";
        Intent shareOnFacebookIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(facebookUri + marketUri));
        startActivity(shareOnFacebookIntent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
yahya.can
  • 1,790
  • 1
  • 11
  • 9
1

How about changing the MIME type to "text/*"?

It seems that Facebook and Twitter can deal with "text/plain" instead of "text/html".

Deepak Swami
  • 3,838
  • 1
  • 31
  • 46
Ziteng Chen
  • 1,959
  • 13
  • 13
  • Is that any chang in menifest file? – Shail Modi Oct 17 '12 at 06:48
  • No you just need to change 'i.setType("text/html"); ' to 'i.setType("text/*"); ' – Ziteng Chen Oct 17 '12 at 07:27
  • Hey ! I have a little problem arise. i used i.setType("text/*"); all application works successfully. but not in facebook. i used edit textbox, which share my message on facebook. please help me to solve it. – Shail Modi Oct 18 '12 at 13:07
  • Probably a bug of Facebook app? see this thread http://stackoverflow.com/questions/7545254/android-and-facebook-share-intent – Ziteng Chen Oct 19 '12 at 03:55