0

I am new to Android. I want to add one Menu by pressing the TextView. Menu should have the Calling & Message & MMS option.
I have successfully implemented this for email using the code below and I want to implement in a similar way Call, SMS and MMS option for my application.

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

                }
            }
        } );
Adinia
  • 3,722
  • 5
  • 40
  • 58
Vinay
  • 1
  • 4

3 Answers3

1

Hope you this is what you are looking for:

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

For help on sending MMS check this link: www.coderanch.com/t/453906/Android/Mobile/send-MMS

A context menu open up on onClick event of the textView.

Kannan Suresh
  • 4,573
  • 3
  • 34
  • 59
  • Hey Amy thanks for your reply . I am Getting this error while using this Code ..11-03 09:59:27.730: ERROR/AndroidRuntime(1877): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=+91-9711347489 } – Vinay Nov 03 '11 at 04:30
  • hey Amy thanks for your help , I got one better way. how u think about this way :-) – Vinay Nov 03 '11 at 07:24
  • The exception is because you wouldn't have added the permission in manifest.xml **** Anyway, good to hear you got your solution. – Kannan Suresh Nov 04 '11 at 04:59
0

I found one better way to do this. I call the value that is passed when pressing Menu:

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();
        }
    });
Adinia
  • 3,722
  • 5
  • 40
  • 58
Vinay
  • 1
  • 4
-1
Intent sIntent = new Intent(Intent.ACTION_CALL, Uri
  .parse("tel:918955499900"));
startActivity(sIntent);

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

Community
  • 1
  • 1
Hemant Menaria
  • 701
  • 1
  • 7
  • 17