How to open Facebook and Twitter in Android

advertisements
  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?


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