Chapter III: interactive communication services and mobile phone control (Send Email)

Effect:

Chapter III: interactive communication services and mobile phone control (Send Email)



Sent successfully

(Note: before it is sent to your phone or mobile phone simulator set-mail)
Set the process I use the 163 mailbox.

Figure:





main.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<Button
android:id="@+id/send"
android:layout_width="93px"
android:layout_height="wrap_content"
android:text="&#21457;&#36865;"
android:layout_x="111px"
android:layout_y="356px"
>
</Button>
<TextView
android:id="@+id/widget31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="&#25910;&#20214;&#20154;:"
android:textSize="19sp"
android:layout_x="28px"
android:layout_y="31px"
>
</TextView>
<EditText
android:id="@+id/receiving"
android:layout_width="179px"
android:layout_height="wrap_content"
android:text=" "
android:textSize="18sp"
android:layout_x="109px"
android:layout_y="19px"
>
</EditText>
<TextView
android:id="@+id/widget33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="&#21457;&#20214;&#20154;:"
android:textSize="19sp"
android:layout_x="45px"
android:layout_y="81px"
>
</TextView>
<EditText
android:id="@+id/accessories"
android:layout_width="182px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="106px"
android:layout_y="68px"
>
</EditText>
<TextView
android:id="@+id/widget35"
android:layout_width="wrap_content"
android:layout_height="26px"
android:text="&#26631;&#39064;:"
android:textSize="19sp"
android:layout_x="50px"
android:layout_y="130px"
>
</TextView>
<EditText
android:id="@+id/title"
android:layout_width="181px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="105px"
android:layout_y="119px"
>
</EditText>
<EditText
android:id="@+id/text"
android:layout_width="296px"
android:layout_height="146px"
android:textSize="18sp"
android:layout_x="11px"
android:layout_y="200px"
>
</EditText>
<TextView
android:id="@+id/widget38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="&#27491;&#25991;"
android:textSize="19sp"
android:layout_x="53px"
android:layout_y="170px"
>
</TextView>
</AbsoluteLayout>



package send.email.test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

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

public class SendEmailTest extends Activity {
        private EditText receiving;
        private EditText accessories;
        private EditText title;
        private EditText text;
        private Button button;
        private String[] reciver;
        private String[] subject;
        private String emailCc;
        private String emailBody;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /**  Loading main.xml*/
        setContentView(R.layout.main);
        /** Found by ID EditText Component */
        receiving =(EditText)findViewById(R.id.receiving);
        accessories=(EditText)findViewById(R.id.accessories);
        title=(EditText)findViewById(R.id.title);
        text=(EditText)findViewById(R.id.text);
        button=(Button)findViewById(R.id.send);
        /** Set Button buttons click event */
        receiving.setOnKeyListener(new EditText.OnKeyListener() {
                public boolean onKey(View v,int keyCode,KeyEvent event){
                        /**Email Is in the correct format */
                        if(isEmail(receiving.getText().toString())){
                                /** Set the Button button a clickable */
                                button.setEnabled(true);
                        }else{
                                /** Sets the Button becomes unavailable to click */
                                button.setEnabled(false);
                        }
                                return false;
                }
                });
        
        
        button.setOnClickListener(new Button.OnClickListener(){
                public void onClick(View v){
                        /** Through Intent sending Email*/
                        Intent intent=new Intent(android.content.Intent.ACTION_SEND);
                        /**
                         * intent.setType("text/plain");  Simulator using this line 
                                 * intent.setType("message/rfc822") ;   Using this on a real machine line 
                                 */
                        intent.setType("plain/text");
                        /** Obtain recipient addresses thrust the body */
                        reciver=new String[]{
                                        receiving.getText().toString()
                        };
                        subject=new String[]{accessories.getText().toString()};
                        emailCc=title.getText().toString();
                        emailBody=text.getText().toString();
                        /** Put a string into intent*/
                        intent.putExtra(android.content.Intent.EXTRA_EMAIL, reciver);
                        intent.putExtra(android.content.Intent.EXTRA_CC, subject);
                        intent.putExtra(android.content.Intent.EXTRA_SUBJECT, emailCc);
                        intent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody);
                        /** Open the Email parameters passed */
                        startActivity(Intent.createChooser(intent, getResources().getString(R.string.send)));
                }
        });
    }
    /** Matching Email is in the correct format */
    public static boolean isEmail(String email){
        String strPattern="\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";      
        Pattern pattern=Pattern.compile(strPattern);
        Matcher matcher=pattern.matcher(email);
        return matcher.find();
    }
}

  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Chapter III: interactive communication services and mobile phone control (Send Email)

  • JAVA EE JSP_JNDI

    dsfdsa http://lindows.javaeye.com/admin/blogs/213348 Tomcat 6 with the connection pool data source configuration http://www.blogjava.net/ec2008/archive/2008/07/19/216063.html project: test Driver path: D: \ workspace \ test \ WebRoot \ WEB-INF \ lib ...

  • Hibernate.cfg.xml configuration file (including the primary key generation strategy Introduction)

    Hibernate.cfg.xml configuration file: <? xml version = "1.0" encoding = "utf-8"?> <! DOCTYPE hibernate-configuration PUBLIC "- / / Hibernate / Hibernate Configuration DTD / / EN" "hibernate-configuration-2.0.dtd

  • The EJB3 Persistence

    EJB3 persistence with Hibernate is very similar to the mechanism: Environment: Server: JBOSS5.0 Database: MySQL5.0 1. Set up a data source First of all, in jboss-5.0.0.GA \ server \ default \ deploy, the establishment of a database used to connect the dat

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • can not be represented as java.sql.Timestamp

    Development of procedures for the use of hibernate when, some time there is no need to fill in the fields, but after the hibernate query time reported "Java.sql.SQLException: Value'0000-00-00 'can not be represented as java.sql.Timestamp ...

  • Spring2.0 + hibernate3.1 + log4j + mysql demo

    applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @ gmail.com

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries