如何通过电子邮件分享广告,广告标题为主题,广告描述为正文

时间:2012-12-10 08:52:31

标签: android json

我是android新手。经过大量的搜索,我在这里发布这个问题。我的应用程序包含在列表视图中显示的广告,我正在尝试通过电子邮件分享广告我已经包含了电子邮件的代码,但它没有从SingleMenuItem.java活动中提取标题以在电子邮件和描述的主题中显示它在Body的位置。我该怎么做才能有人帮忙吗?以下是代码

Email.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));   
          }
        });
             }
            }

2 个答案:

答案 0 :(得分: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 :"));
}

答案 1 :(得分:0)

在您的情况下,无需创建Email.class只需在email3按钮的单击侦听器中编写您的Email Intent代码。

代码应如下所示。

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"));
           }
        });