Shail Modi
Shail Modi

Reputation: 27

How to open Facebook and Twitter in android

  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?

Upvotes: 2

Views: 281

Answers (2)

yahya.can
yahya.can

Reputation: 1810

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();
    }
}

Upvotes: 5

Ziteng Chen
Ziteng Chen

Reputation: 1969

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

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

Upvotes: 1

Related Questions