表格发送电子邮件,Android

时间:2013-08-07 08:07:35

标签: android email android-intent

这个主题在这里和互联网上有详细记载,但我仍然遇到这个问题,尝试了各种代码。

我的代码看起来很好,但按下发送按钮时没有动作。

我已将ReportProblemMail活动添加到我的Manifest文件中,我是否缺少任何权限?

非常感谢您的帮助。

reportproblem.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="To : "
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/to_edit_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Subject : "
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/subject_edit_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Message : "
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/message_edit_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="top"
        android:inputType="textMultiLine"
        android:lines="5" />

    <Button
        android:id="@+id/send_email_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Send" />

</LinearLayout>

ReportProblemMail.java

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

        public class ReportProblemMail extends Activity {

            Button mSendButton;
            EditText mTo;
            EditText mSubject;
            EditText mMessage;

            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.reportproblem);

                mSendButton = (Button) findViewById(R.id.send_email_button);
                mTo = (EditText) findViewById(R.id.to_edit_text);
                mSubject = (EditText) findViewById(R.id.subject_edit_text);
                mMessage = (EditText) findViewById(R.id.message_edit_text);

                mSendButton.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {

                      String to = mTo.getText().toString();
                      String subject = mSubject.getText().toString();
                      String message = mMessage.getText().toString();

                      Intent email = new Intent(Intent.ACTION_SEND);
                      email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
                      email.putExtra(Intent.EXTRA_SUBJECT, subject);
                      email.putExtra(Intent.EXTRA_TEXT, message);

                      //prompts email client only
                      email.setType("message/rfc822");

                      startActivity(Intent.createChooser(email, "Choose an Email client :"));

                    }
                });
            }
        }

ReportProblemMail.java

用toast

@Override
            public void onClick(View v) {

                Toast.makeText(getApplicationContext(), 
                        "Button is clicked", Toast.LENGTH_LONG).show();

              String to = mTo.getText().toString();
              String subject = mSubject.getText().toString();
              String message = mMessage.getText().toString();

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="burger.van"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="burger.van.SplashScreen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />


            </intent-filter>



        </activity>

        <activity
            android:label="@string/app_name"
            android:name="burger.van.MainActivity" >
        </activity>

        <activity
            android:label="@string/app_name"
            android:name="burger.van.AboutActivity" >
        </activity>

        <activity
            android:label="@string/app_name"
            android:name="burger.van.SubmitVanActivity" >
        </activity>

        <activity
            android:label="@string/app_name"
            android:name="burger.vanlocator.ReportProblemActivity" >
        </activity>



        <activity
            android:label="@string/app_name"
            android:name="burger.van.ReportProblemMail" >
        </activity>



    </application>

</manifest>

0 个答案:

没有答案
相关问题