2014-12-17 18 views
5

Bu konuda yeniyim, fakat kod snippet'ımın nesi yanlış? Hatayı alıyorum: Bağlantıyı seçtiğimde 'Bu eylem şu anda desteklenmiyor'.Mailto Android: 'Desteklenmeyen eylem' hatası

public void addEmail() { 

    TextView txt = (TextView) findViewById(R.id.emailtext); 

    txt.setOnClickListener(new View.OnClickListener(){ 


     public void onClick(View v){ 
      Intent intent = new Intent(); 
      String uriText = 
        "mailto:[email protected]" + 
        "?subject=" + URLEncoder.encode("some subject text here") + 
        "&body=" + URLEncoder.encode("some text here"); 

       Uri uri = Uri.parse(uriText); 

       Intent sendIntent = new Intent(Intent.ACTION_SENDTO); 
       sendIntent.setData(uri); 
       startActivity(Intent.createChooser(sendIntent, "Send email")); 

    }}); 

} 

Çok teşekkürler: İşte benim kodudur!

+0

@see https://stackoverflow.com/questions/2197741/how-can-i-send-emails-from-:

Bu kodu kullanarak niyet başlatmaya çalışırken önce bu algılayabilir my-android-application – shkschneider

+0

@shkschneider, bu hataya nasıl hitap ediyor? – Sam

+0

Android e-posta istemcisinde henüz bir e-posta hesabı kurmamışken Android 4.0.2 öykünücüsünde buna rastladım. İstemcide bir hesap oluşturmak problemin etrafında çalıştı. – Sam

cevap

1

benim için çalıştı, bu deneyin:

public void addEmail() { 

    TextView txt = (TextView) findViewById(R.id.emailtext); 

    txt.setOnClickListener(new View.OnClickListener(){ 

    public void onClick(View v){ 

      String[] emails = {"[email protected]"}; 
      String subject = "your subject"; 
      String message = "your message"; 

      Intent email = new Intent(Intent.ACTION_SEND); 
      email.putExtra(Intent.EXTRA_EMAIL, emails); 
      email.putExtra(Intent.EXTRA_SUBJECT, subject); 
      email.putExtra(Intent.EXTRA_TEXT, message); 

      // need this to prompts email client only 
      email.setType("message/rfc822"); 

      startActivity(Intent.createChooser(email, "Choose an Email client :")); 
    }}); 

} 
+0

Bunun çalıştığını test ettim ve onaylıyorum. Hiçbir uygulama niyetle eşleşmediğinde 'setData()' yönteminin kullanılmasıyla ilgili sorun oluştu. – Sam

13

sorun resmi Android emülatörlerine birinde doluyorsa ve henüz üzerinde bir e-posta hesabı kurmadığınızı muhtemelen. Emülatörler bu olduğunda com.android.fallback.Fallback etkinliğini açar, ancak bu gerçek dünyadaki cihazlarda gerçekleşmez.

ComponentName emailApp = intent.resolveActivity(getPackageManager()); 
ComponentName unsupportedAction = ComponentName.unflattenFromString("com.android.fallback/.Fallback"); 
boolean hasEmailApp = emailApp != null && !emailApp.equals(unsupportedAction);