1
public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btn1 = (Button) findViewById(R.id.button1);
        Button btn2 = (Button) findViewById(R.id.button2);
        Button btn3 = (Button) findViewById(R.id.button3);
        Button btn4 = (Button) findViewById(R.id.button4);

        btn1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                String categoryName = "This is share data";

                try {
                    Intent emailIntent = new Intent(
                            android.content.Intent.ACTION_SEND);
                    String[] recipients = new String[] { "Enter email" };
                    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                            recipients);
                    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                            "Email:- " + categoryName);

                    emailIntent.setType("message/rfc822");
                    // emailIntent.setType("text/html");
                    startActivity(emailIntent);
                } catch (Exception e) {
                    String ss = e.getMessage();
                    Log.e("The error is :", ss);
                    e.printStackTrace();
                }

            }
        });

        btn2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                String title = "This is facebook Data";

                try {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse("https://m.facebook.com/sharer.php?u="
                            + "www.facebook.com" + "&t=" + title + "&_rdr"));
                    startActivity(i);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        btn3.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                String title = "This Twitter";
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse("https://twitter.com/intent/tweet?text="
                        + title + "&url=" + "https://www.twitter.com"));
                startActivity(i);

            }
        });

        btn4.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                // for Linkeind

            }
        });

    }

}

检查我的代码是否能够将数据共享到 Facebook 邮件和 twitter 我也想共享它链接在我已经创建 button4 功能用于将数据共享到 LinkedIn 所以请帮助我如何做到这一点我第一次这样做是学习者无法做这个

4

0 回答 0