2012-08-29 32 views
0

我想要一個簡單的電子郵件application.I稱此鏈接 http://www.mkyong.com/android/how-to-send-email-in-android/的電子郵件應用程序給錯誤「沒有應用程序可執行此操作」

但我得到一個錯誤作爲模擬器「沒有應用程序可執行此操作」以及如何在真正的設備上。如何克服這個錯誤。如上面鏈接中提到的發送按鈕,選擇一個電子郵件客戶端選項出現。如何獲得這個?有人可以指導我PLZ。 Thanx提前。 我的代碼是:

package com.example.androidsample4; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 

public class MakeComment extends Activity 
{ 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.comment); 
     TextView tv1=(TextView)findViewById(R.id.textView1); 
     TextView tv2=(TextView)findViewById(R.id.textView2); 
     TextView tv3=(TextView)findViewById(R.id.textView3); 
     TextView tv4=(TextView)findViewById(R.id.textView4); 
     TextView tv5=(TextView)findViewById(R.id.textView5); 
     final EditText ed1=(EditText)findViewById(R.id.editText1); 
     EditText ed2=(EditText)findViewById(R.id.editText2); 
     final EditText ed3=(EditText)findViewById(R.id.editText3); 
     final EditText ed4=(EditText)findViewById(R.id.editText4); 
     ed3.setKeyListener(null); 
     Button b1=(Button)findViewById(R.id.button1); 
     b1.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
        //String to = ed3.getText().toString(); 
        String name = ed1.getText().toString(); 
        String message = ed4.getText().toString(); 

        Intent email = new Intent(Intent.ACTION_SENDTO); 
       // email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to}); 
        //email.putExtra(Intent.EXTRA_CC, new String[]{ to}); 
        //email.putExtra(Intent.EXTRA_BCC, new String[]{to}); 
        email.putExtra(Intent.EXTRA_SUBJECT, name); 
        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 :")); 

      } 
     }); 
    } 

} 
+1

你應該在你的設備或eumalator安裝gmail – Sameer

回答

1

,除非你安裝可以處理郵件的應用程序,不會在模擬器上工作。默認情況下不安裝這樣的應用程序。嘗試在您的真實設備上安裝電子郵件客戶端並重新測試。

+0

好吧,我會試試這個,讓你知道 – user1387035

-1

我們不能告訴你你錯在哪裏,因爲你還沒有發佈你的代碼。嘗試下面的代碼(在設備和模擬器上都可以),如果它工作正常,那麼你的部分出現了問題,如果不嘗試安裝另一個電子郵件客戶端。

TextView email = (TextView) findViewById(R.id.email); 
email.setText(Html.fromHtml("<a href=\"mailto:[email protected]\">E-mail</a>")); 
email.setMovementMethod(LinkMovementMethod.getInstance()); 

「選擇電子郵件客戶端選項」 - 該窗口由Android自動填充。

+0

我現在會發布我的代碼 – user1387035

+1

將Intent.ACTION_SENDTO更改爲'Intent.ACTION_SEND' – ThePCWizard

0

試試這個:

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
      "mailto","[email protected]", null)); 
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "EXTRA_SUBJECT"); 
startActivity(Intent.createChooser(emailIntent, "Send email...")); 

希望這有助於。

相關問題