2014-02-12 2 views
15

사용자가 이메일을 보내 일부 데이터를 공유 할 수있는 기능을 제공해야합니다. 아래 코드를 사용했습니다.버튼을 클릭하면 Android 앱에서 이메일이 전송됩니다.

Intent email = new Intent(android.content.Intent.ACTION_SENDTO); 
    email.setType("message/rfc822"); 
    email.putExtra(Intent.EXTRA_EMAIL, new String[] { to }); 
    email.putExtra(Intent.EXTRA_SUBJECT, subject); 
    email.putExtra(Intent.EXTRA_TEXT, message); 
    startActivity(Intent.createChooser(email,"Choose an Email client :")); 

이 이메일, Gmail은, Skype를 보여주고 사용자가 선택할 수있는 블루투스를 통해 전송합니다. 나는이 목록에서 블루투스를 통해 사용자에게 Skype를 보여주고 싶지 않다. 내가해야하는 것 ? 나는 똑같은 일을하지만 목록에있는 이메일, 블루투스 (설정 -> 도움말 -> 연락처 -> ...)를 표시하지 않는 WhatsApp을 가지고 있는데 목록에있는 이메일과 Gmail 만 표시합니다. 나는 똑같이해야한다. Gmail을 통해 공유 할 수

답변

19

를 호출해야 JUS : 특정받는 사람이없는 경우

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
      "mailto","[email protected]", null)); 
intent.putExtra(Intent.EXTRA_SUBJECT, subject); 
intent.putExtra(Intent.EXTRA_TEXT, message); 
startActivity(Intent.createChooser(intent, "Choose an Email client :")); 

- 다음과 같이 이동 :

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
      "mailto", "", null)); 
+0

나는 그것을 검사한다. 나는 스카 이프가 아닌 목록에있는 메일 클라이언트 (Gmail, Yahoo, Outlook) 만 원한다. bluetooth를 통해 보내라. 내가하는 ..? – Amardeepvijay

+0

@Amardeep 내 답변을 수정했습니다. 그러나 WhatsApp는 여전히 이메일 클라이언트가 2 개 이상이라도 목록에있는 2 개의 이메일 클라이언트 (Gmail 및 이메일) 만 표시하는 사용자 지정 대화 상자를 사용합니다. – localhost

+0

실제 장치에서 작동하지 않습니다. 이 email.setType ("message/rfc822");을 사용할 수 있습니까? – Amardeepvijay

0

사용이 방법은 당신이 시도

startActivity(getSendEmailIntent(context, email,subject, body)); 





public Intent getSendEmailIntent(Context context, String email, 
        String subject, String body) { 
      Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 

      try { 

       // Explicitly only use Gmail to send 
       emailIntent.setClassName("com.google.android.gm", 
         "com.google.android.gm.ComposeActivityGmail"); 

       emailIntent.setType("text/html"); 

       // Add the recipients 
       if (email != null) 
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
          new String[] { email }); 

       if (subject != null) 
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
          subject); 

       if (body != null) 
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body)); 

       // Add the attachment by specifying a reference to our custom 
       // ContentProvider 
       // and the specific file of interest 
       // emailIntent.putExtra(
       // Intent.EXTRA_STREAM, 
       // Uri.parse("content://" + CachedFileProvider.AUTHORITY + "/" 
       // + fileName)); 

       return emailIntent; 
    //   myContext.startActivity(emailIntent); 
      } catch (Exception e) { 
       emailIntent.setType("text/html"); 

       // Add the recipients 
       if (email != null) 
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
          new String[] { email }); 

       if (subject != null) 
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
          subject); 

       if (body != null) 
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body)); 

    //   myContext.startActivity(Intent.createChooser(emailIntent, 
    //     "Share Via")); 
       return emailIntent; 
      } 
      } 
관련 문제