2011-11-02 53 views
0

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

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

       } 
      } 
     }); 

回答

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

有关发送MMS帮助检查此链接: www.coderanch.com/ t/453906/Android/Mobile/send-MMS

在onClick e上打开一个上下文菜单textView的发泄。

+0

嘿艾米谢谢你的回复。使用此代码时出现此错误。11-03 09:59:27.730:错误/ AndroidRuntime(1877):android.content.ActivityNotFoundException:未找到处理Intent的活动{act = android.intent.action.CALL dat = + 91-9711347489} – Vinay

+0

嘿艾米谢谢你的帮助,我有一个更好的办法。你怎么看待这个问题:-) – Vinay

+0

这个例外是因为你没有在manifest.xml中添加权限** **无论如何,很高兴听到你有你的解决方案。 – Ian