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



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

电子邮件.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..."));
                }

        });
      }
     }

单菜单项活动.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));   
          }
        });
             }
            }
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 :"));
}
在您

的情况下,无需创建Email.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"));
           }
        });

相关内容

最新更新