Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 按钮打开活动特定_Java_Android_Android Activity - Fatal编程技术网

Java 按钮打开活动特定

Java 按钮打开活动特定,java,android,android-activity,Java,Android,Android Activity,我将尽可能具体地说明这一点。我有一个钮扣。此按钮称为“发送”。当用户单击“发送”按钮时,我希望我的应用程序自动将电子邮件发送到我的收件箱。问题是,每次我问这个问题,这里的人都会告诉我,“选择一个电子邮件客户端”。我不要这个。下面是一个场景,用户在第一个框中键入“他的”电子邮件。然后将“文本”放入下面的框中。当该用户单击“发送”时,应用程序应自动将该信息发送到我的电子邮件收件箱 我的EmailActivity.java如下 import android.app.Activity;

我将尽可能具体地说明这一点。我有一个钮扣。此按钮称为“发送”。当用户单击“发送”按钮时,我希望我的应用程序自动将电子邮件发送到我的收件箱。问题是,每次我问这个问题,这里的人都会告诉我,“选择一个电子邮件客户端”。我不要这个。下面是一个场景,用户在第一个框中键入“他的”电子邮件。然后将“文本”放入下面的框中。当该用户单击“发送”时,应用程序应自动将该信息发送到我的电子邮件收件箱

我的EmailActivity.java如下

    import android.app.Activity;
    import android.content.ActivityNotFoundException;
    import android.content.ComponentName;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;


    public class EmailActivity extends Activity {
    ;

    Button buttonSend;
    EditText textTo;
    EditText textSubject;
    EditText textMessage;

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



    buttonSend = (Button) findViewById(R.id.buttonSend);
    textTo = (EditText) findViewById(R.id.editTextTo);
    textSubject = (EditText) findViewById(R.id.editTextSubject);
    textMessage = (EditText) findViewById(R.id.editTextMessage);

    buttonSend.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                    "mailto","r2kbeastgaming4us.com", null));

            String to = textTo.getText().toString();
            String subject = textSubject.getText().toString();
            String message = textMessage.getText().toString();

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

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

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

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

    <TextView
    android:id="@+id/textViewPhoneNo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Email : "
    android:textAppearance="?android:attr/textAppearanceLarge" />

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

    <requestFocus />

    </EditText>

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

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

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

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

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

    </LinearLayout>
}

我的电子邮件布局如下

    import android.app.Activity;
    import android.content.ActivityNotFoundException;
    import android.content.ComponentName;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;


    public class EmailActivity extends Activity {
    ;

    Button buttonSend;
    EditText textTo;
    EditText textSubject;
    EditText textMessage;

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



    buttonSend = (Button) findViewById(R.id.buttonSend);
    textTo = (EditText) findViewById(R.id.editTextTo);
    textSubject = (EditText) findViewById(R.id.editTextSubject);
    textMessage = (EditText) findViewById(R.id.editTextMessage);

    buttonSend.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                    "mailto","r2kbeastgaming4us.com", null));

            String to = textTo.getText().toString();
            String subject = textSubject.getText().toString();
            String message = textMessage.getText().toString();

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

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

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

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

    <TextView
    android:id="@+id/textViewPhoneNo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Email : "
    android:textAppearance="?android:attr/textAppearanceLarge" />

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

    <requestFocus />

    </EditText>

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

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

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

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

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

    </LinearLayout>

你必须从你的应用程序中显式地调用gmail,为此你必须提及软件包名称。试试下面的代码

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                    "mailto","r2kbeastgaming4us.com", null));

            String to = textTo.getText().toString();
            String subject = textSubject.getText().toString();
            String message = textMessage.getText().toString();

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

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

          **email.setPackage("com.google.android.gm");**

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

为此,您必须将这些信息发送到web服务,web服务将向该服务发送电子邮件account@VivekMishra我将如何做到这一点?有任何地方可以链接我吗?你必须咨询后端开发人员,如php等