views:

43

answers:

1

Hi,

I am trying to a menu item to launch the Send intent. This is what I did, I see the menu item but i don't see send intent launch when i select the menu item.

public void onCreateContextMenu(ContextMenu menu, View v,
    ContextMenuInfo menuInfo) {
      Intent sendIntent = new Intent(Intent.Action_Send);
      menu.add(Menu.NONE, 0, 0, "testmenu").setIntent(sendIntent);
    }
  }
}

Thank you.

A: 
@Override
   public void onCreateContextMenu(ContextMenu menu, View v,
                ContextMenuInfo menuInfo) {
            super.onCreateContextMenu(menu, v, menuInfo);           
            menu.add(0, 1,0,"SEND TEST");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
            Intent sendIntent = new Intent(Intent.Action_Send);
             switch(item.getItemId()) {
                case 1:
                 //DO WHATEVER YOU WANT HERE
                       return true;
            }
            return super.onContextItemSelected(item);
        }

Depending on what you want to send. A simple message I assume. I would do something like this in the "onContextItemSelected":

//First define up top before oncreate. 
private SmsManager sm = SmsManager.getDefault();
private String number = "9995551111";
//then...
@Override
public boolean onContextItemSelected(MenuItem item) {

             switch(item.getItemId()) {
                case 1:
                 sm.sendTextMessage(number, null, "Test Message", null, null);
                     return true;
            }
            return super.onContextItemSelected(item);
        }
///DONT FORGET TO ADD THE USES PERMISSION TO SEND MESSAGES IN YOUR MANIFEST!!!

You could also create an activity with views to assign a number and user input a message. and run sm.sendTextMessage with an onClickListener. You would start the activity in the "DO WHATEVER" area of the first example. There is more info on sending SMS right Here

Brian