2012-02-15 31 views
7

Tôi là người mới bắt đầu sử dụng Android. Tôi cần biết là có bất kỳ ý định nào để mở cửa sổ Tạo Tin nhắn. Tôi đã thử với mã này -Android: Message Intent

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

Nhưng, nó tăng lên, Gmail, Email & Message Tôi chỉ cần gửi thư. Trong ứng dụng của tôi, tôi đã tích hợp điều này khi tôi nhấn nút. Ai có thể biết điều này? Hướng dẫn tôi.

Trả lời

7

Bạn có thể chỉ trong file xml của bạn thêm

android:onClick = "onClick" 

và trong hoạt động:

//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

Có này hoạt động tốt. Cảm ơn bạn. –

+0

Nếu bạn chỉ có thể trả lời :) – goodm

+1

Tôi không thể chấp nhận ngay bây giờ. Nó nói với tôi "Bạn chỉ có thể chấp nhận câu trả lời này trong vòng 3 phút. –

0

Tôi đoán này nên làm việc:

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

Cảm ơn thông tin quý giá của bạn. –

1

này sẽ giúp bạn:

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

Cảm ơn thông tin quý giá của bạn. –

4

Hãy thử điều này:

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

Sử dụng chỉ như thế này cho tất cả các ứng dụng sẽ chấp nhận điều này ý định

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; 
Các vấn đề liên quan