如何在Android中打开Facebook和Twitter

Sha*_*odi 2 android android-intent

  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"));
Run Code Online (Sandbox Code Playgroud)

我无法在Android中使用此代码打开Facebook和Twitter,但其他应用程序(如Gmail和Skype)已成功打开.为什么?我如何打开Facebook和Twitter?

yah*_*can 5

你能试试这段代码吗:

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();
    }
}
Run Code Online (Sandbox Code Playgroud)