创建电话&带有intent.Action_send的SMS菜单选项

时间:2011-11-02 09:01:20

标签: android android-widget

我是Android新手。我想通过按TextView添加一个菜单。菜单应该有Calling&消息&彩信选项。
我已经使用下面的代码成功实现了这个电子邮件,我想以类似的方式实现我的应用程序的呼叫,短信和彩信选项。

tv4.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent i = new Intent(android.content.Intent.ACTION_SEND);

                i.setType("html/plain");
                i.putExtra(Intent.EXTRA_EMAIL  , new String[]{bean.getOfficialemailid()});
                i.putExtra(Intent.EXTRA_SUBJECT, "Official");
                i.putExtra(Intent.EXTRA_TEXT   , "Have a Great Day");
                try {
                    startActivity(Intent.createChooser(i, "SEND EMAIL"));
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(Database_display_activity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();

                }
            }
        } );

3 个答案:

答案 0 :(得分:1)

希望你这就是你想要的:

private static final int SMS = 0;
private static final int MMS = 1;
private static final int CALL = 2;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

    TextView textView = (TextView) findViewById(R.id.textView1);

textView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    menu.add(0, 0, 0, "SMS");
    menu.add(0, 1, 1, "MMS");
    menu.add(0, 2, 2, "Call");
    }
});

textView.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    openContextMenu(v); 
    }
});
}

@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();

switch (item.getItemId()) {

case SMS:
    //Code for sending SMS

    break;

case MMS:
    //Code for sending MMS

    break;

case CALL:
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + phoneNumber));
    startActivity(callIntent);

    break;


default:
    return super.onContextItemSelected(item);
}

return true;
}

有关发送彩信的帮助,请查看此链接: www.coderanch.com/t/453906/Android/Mobile/send-MMS

在textView的onClick事件上打开一个上下文菜单。

答案 1 :(得分:0)

我发现了一种更好的方法。我调用按菜单时传递的值:

tv3.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        // TODO Auto-generated method stub
        builder.setItems(R.array.OPTIONS, new DialogInterface.OnClickListener() {
       @Override
    public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
         switch (which) {
         case 0:{
             Intent callIntent = new Intent(Intent.ACTION_CALL);
             callIntent.setData(Uri.parse("tel:" + bean.getPhoneno()));
             startActivity(callIntent);
         }break;
         case 1 :{

         }break;
         }

               }
            });
            builder.show();
        }
    });

答案 2 :(得分:-1)

Intent sIntent = new Intent(Intent.ACTION_CALL, Uri
  .parse("tel:918955499900"));
startActivity(sIntent);

更多:How to make a phone call in android and come back to my activity when the call is done?