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

Effect:

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

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:

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

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

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

分类:Mobile 时间:2011-01-13 人气:134
分享到:
blog comments powered by Disqus

相关文章

  • Chapter III download. Install Android SDK 2010-03-29

    Key skills and concepts l download the Android SDK l use the update feature in Eclipse l download, install and configure Eclipse's Android plug-in l Detection of PATH Statement Previous section, you have to download and install the main development e

  • Chapter III: interactive communication services and mobile phone control 2011-01-13

    Effect: Click the link below to access the call interface main.xml <?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:id="@+id/widget0" android:layout_width="fill_parent" android:layout_height=&

  • Chapter III Servlet Programming 2010-03-29

    Chapter III Servlet Programming 3.2 servlet structure and Servlet-related classes, interfaces are defined in the javax.servlet and javax.servlet.http these two packages, the You can download java ee api documentation to see. javax.servlet package def

  • Chapter III Extjs in the development, how to achieve code reuse (Getting Started tutorial) 2009-10-02

    Chapter III Extjs in the development, how to achieve code reuse (Getting Started tutorial) If you want to achieve the following interface, you will choose the kind of code? Code 1: Code 2: According to the above created object: You will choose? ? Rec

  • Translation How Tomcat Works coder love the first part of Chapter III 2010-11-05

    Chapter III: Connector Before the formal start this application, we first used under the StringManager org.apache.catalina.util package as a start. This class is used to process the application and Cacalina error message itself international. The Str

  • sed and awk rookie notes - Chapter III understand Regular Expressions 2010-12-28

    Chapter III understand Regular Expressions The third chapter is the most important, a lot of regular expressions together with the work of all wonderful, so be sure to learn! P45: Summary of special characters. P54: POSIX character classes ([: space:

  • Select sub-section (Chapter III) 2011-05-29

    In real mode, the logical address space in the memory cell's address within the segment value and the segment offset of two parts. In protected mode, virtual address space (the equivalent of logical address space) in the address storage unit by the s

  • Chapter III: delete check by phone to change (SQLiteOpenHelper) 2011-01-14

    Effect: 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://

  • Chapter IV to explore Android SDK 2010-03-29

    Key skills and concepts l using the Android SDK documentation l using the Android SDK tools l use application examples l to understand the life cycle of Android applications Since you have already built good development environment, you can explore t

  • [Transfer] Microsoft Mobile access to examples of WCF services 2010-11-03

    Original Address http://www.po-soft.com/hi/csh/blog/418 Microsoft Mobile access the WCF Service example This article describes the establishment of a WCF service on a PC, then create a mobile client to access the WCF service. Issues involved are as f

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.221 (s). 12 q(s)