为什么我的意图没有开始活动?

时间:2014-10-07 15:56:32

标签: android android-intent

我的代码是:

Intent i = new Intent(Intent.ACTION_SENDTO);
i.putExtra(Intent.EXTRA_EMAIL,"example @example. Com");
i.putExtra(Intent.EXTRA_SUBJECT,"Grannylaunch Support Needed:" + System.currentTimeMillis());
startActivity(i);
Toast.makeText(getApplicationContext(),"Emailing Support....", Toast.LENGTH_LONG);

我的问题是意图不是开始一项活动。我做错了什么,如何解决?

我尝试过设置intent = Intent.ActionSend,但不起作用。

编辑 -

Intent i = new Intent(Intent.ACTION_SENDTO);
i.putExtra(Intent.EXTRA_EMAIL,"example@example.com");
i.putExtra(Intent.EXTRA_SUBJECT,"Grannylaunch Support Needed:" + System.currentTimeMillis());
i.putExtra(Intent.EXTRA_TEXT,"");
startActivity(i);
Toast.makeText(getApplicationContext(),"Emailing Support....", Toast.LENGTH_LONG); 

这也不起作用。

4 个答案:

答案 0 :(得分:5)

protected void sendEmail() {
      Log.i("Send email", "");

      String[] TO = {"amrood.admin@gmail.com"};
      String[] CC = {"mcmohd@gmail.com"};
      Intent emailIntent = new Intent(Intent.ACTION_SEND);
      emailIntent.setData(Uri.parse("mailto:"));
      emailIntent.setType("text/plain");


      emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
      emailIntent.putExtra(Intent.EXTRA_CC, CC);
      emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
      emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");

      try {
         startActivity(Intent.createChooser(emailIntent, "Send mail..."));
         finish();
         Log.i("Finished sending email...", "");
      } catch (android.content.ActivityNotFoundException ex) {
         Toast.makeText(MainActivity.this, 
         "There is no email client installed.", Toast.LENGTH_SHORT).show();
      }
  

试试这可能有助于你

答案 1 :(得分:2)

您需要在默认的电子邮件应用程序中配置电子邮件帐户。

 Intent email = new Intent(Intent.ACTION_SEND);
                    email.setType("plain/text");
                    email.putExtra(Intent.EXTRA_EMAIL,
                            new String[] { abc@gmail.com) });
                    email.putExtra(Intent.EXTRA_SUBJECT, "");
                    email.putExtra(Intent.EXTRA_TEXT,"");
                    startActivity(Intent.createChooser(email,
                            "Choose an Email client :"));

答案 2 :(得分:0)

试试这段代码:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

答案 3 :(得分:0)

Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("plain/text");
                    intent.putExtra(Intent.EXTRA_EMAIL, new String[]
                    { RECEIVER_EMIAL_ID });
                    // intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
                    // intent.putExtra(Intent.EXTRA_TEXT, "mail body");
                    startActivity(Intent.createChooser(intent, "Choose mail client"));