0

我是安卓新手。经过大量搜索后,我在这里发布了这个问题。我的应用程序包含在列表视图中显示的广告,我正在尝试通过电子邮件共享广告我已经包含了电子邮件代码,但它没有从 SingleMenuItem.java Activity 中提取标题以将其显示在电子邮件的主题中,并在正文的描述中显示. 我该怎么做有人可以帮忙吗?以下是代码

电子邮件.java

  public class Email extends Activity {
  Button  send;
  EditText address, subject, emailtext;
   @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.email);
  send=(Button ) findViewById(R.id.send);
  address=(EditText) findViewById(R.id.emailaddress);
  subject=(EditText) findViewById(R.id.emailsubject);
  emailtext=(EditText) findViewById(R.id.emailtext);

  send.setOnClickListener(new OnClickListener() {

                public void onClick(View  v) {
                        // TODO Auto-generated method stub

               final Intent emailIntent = new         Intent(android.content.Intent.ACTION_SEND);

                               emailIntent.setType("plain/text");

         emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String []{ address.getText().toString()});

                                  emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());

                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());

                            Email.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));

                }


        });
      }
     }

SingleMenuItemActivity.java

    public class SingleMenuItemActivity  extends Activity {

         // JSON node keys
             private static final String TAG_TITLE = "title";
             private static final String TAG_DATE = "date";
             private static final String TAG_NAME = "name";
             private static final String TAG_CONTENT = "content";
         @Override
            public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
            setContentView(R.layout.single_list_item);


      // getting intent data
      Intent in = getIntent();

       // Get JSON values from previous intent
      String title = in.getStringExtra(TAG_TITLE);
      String date = in.getStringExtra(TAG_DATE);
      String name = in.getStringExtra(TAG_NAME);
      String content = in.getStringExtra(TAG_CONTENT);

     // Displaying all values on the screen
        TextView lblName = (TextView) findViewById(R.id.name_label);
        TextView lblCost = (TextView) findViewById(R.id.email_label);
        TextView lblDesc = (TextView) findViewById(R.id.mobile_label);
        TextView lblCont = (TextView) findViewById(R.id.content_label);

       lblName.setText(title);
       lblCost.setText(date);
       lblDesc.setText(name);
       lblCont.setText(content);

      final ImageView email3 = (ImageView) findViewById(R.id.email);


       email3.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v){
              //my codes
             startActivity(new Intent(SingleMenuItemActivity.this, Email.class));   
          }
        });
             }
            }
4

2 回答 2

0
private void sendMail(String appName, String adLink) {
    String msg = "<HTML><BODY>Hello,<br>Recently,I downloaded <b><font color=\"red\">"+appName+"</font></b>"+
" from Play Store.I found this very challenging and a great game."+
            "<br>I would like to suggest you this game.<br><br><a href="+playStoreLink+">Download</a><br><br>"+
"<br>Thank You</BODY></HTML>";
    String sub = "Get it now. It is there in Play Store";
    Intent email = new Intent(Intent.ACTION_SEND);
    email.setType("text/html");
    email.putExtra(Intent.EXTRA_SUBJECT, sub);
    email.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(msg));
    email.setType("message/rfc822");
    startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
于 2012-12-10T09:39:34.390 回答
0

在您的情况下,无需创建只需在ButtonEmail.class的单击侦听器中编写您的电子邮件意图代码。email3

代码应如下所示。

email3.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v){
                //my codes
             Intent emailIntent = Intent(android.content.Intent.ACTION_SENDTO);
        emailIntent.setType("text/html");
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, content));
        startActivity(Intent.createChooser(emailIntent, "Email to Friend"));
           }
        });
于 2012-12-11T12:35:51.010 回答