2012-02-15 69 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;