2012-02-15 70 views
7

我是一个初学者到android。我需要知道是否有任何意图打开创建消息窗口。我试着用这个代码 -Android:消息意图

Intent i = new Intent(Intent.ACTION_SEND); 
i.setType("text/plain"); 

但是,它提出,Gmail, Email & Message我需要筹集唯一的消息。在我的应用程序中,当我按下按钮时,我必须将其整合。任何人都可以知道吗?引导我。

回答

7

您可以直接在XML文件中添加

android:onClick = "onClick" 

和活动:

//main buttons listener 
public void onClick(View view) 
{ 
    switch (view.getId()) 
    { 
      case R.id.sms: 
      Intent intentsms = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + "")); 
      intentsms.putExtra("sms_body", "Test text..."); 
      startActivity(intentsms); 
      break; 
    } 
} 
+0

是能正常工作。谢谢。 – 2012-02-15 09:35:52

+0

如果你能把我的答案:) – goodm 2012-02-15 09:38:14

+1

我现在不能接受。它告诉我:“您只能在3分钟内接受这个答案。 – 2012-02-15 09:39:43

0

我想这应该工作:

i.addCategory(Intent.CATEGORY_DEFAULT); 
i.setType("vnd.android-dir/mms-sms"); 
+0

感谢您提供宝贵的信息。 – 2012-02-15 09:36:47

1

这将帮助你:

Intent sendIntent = new Intent(Intent.ACTION_VIEW); 
sendIntent.setType("vnd.android-dir/mms-sms"); 
startActivity(sendIntent); 
+0

感谢您提供宝贵的信息。 – 2012-02-15 09:37:23

4

试试这个:

Intent i = new Intent(Intent.ACTION_SEND); 
i.setType("text/plain"); 
i.putExtra(Intent.EXTRA_EMAIL , new String[] { "[email protected]" }); 
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email"); 
i.putExtra(Intent.EXTRA_TEXT , "body of email"); 
try { 
    startActivity(Intent.createChooser(i, "Send mail...")); 
} catch (android.content.ActivityNotFoundException ex) { 
    Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show(); 
} 
1

使用就这样对所有的应用程序将接受这个意图

case R.id.action_shareapp: 
      Intent send = new Intent(Intent.ACTION_SEND); 
      send.setType("text/plain"); 
      send.putExtra(
        Intent.EXTRA_TEXT, 
        "Checkout this coool App follow this link. https://play.google.com/store/apps/details?id=com.picknget.android"); 
      startActivity(Intent.createChooser(send, "Share with")); 
      break;