如何通过对话框发送消息?

时间:2011-08-16 10:41:48

标签: android

在我的应用程序中,我点击一个共享图像按钮,通过警告对话框显示四个选项facebook,twitter,mail和messaging。我想通过第四个选项(消息传递)发送消息。怎么做。我已经创建了这样的对话框。什么是将消息发送给任何暴徒的代码。

这是我的代码.....

sharebuton.setOnClickListener(new View.OnClickListener() {
        @Override`enter code here`
        public void onClick(View v) {
            // TODO Auto-generated method stub
    final CharSequence[] items = {"Facebook","Twitter", "E-Mail", "Messaging"};
    AlertDialog.Builder builder = new AlertDialog.Builder(ProgramInfoActivity.this);
    builder.setTitle("Share the Program");
    builder.setItems(items, new DialogInterface.OnClickListener() {   
        public void onClick(DialogInterface dialog, int item) {   
            //Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();          
            }});
    AlertDialog alert = builder.create();
    alert.show();

        }
    });

1 个答案:

答案 0 :(得分:2)

您可以使用默认共享意图。

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "message subject");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text");
startActivity(Intent.createChooser(shareIntent, "Pick a Share method"));
相关问题