单击按钮时直接到 android-mail 客户端

Direct to android-mail client when clicking a button

hi,

this is a single Item View of a ListView. I wan't to go to email client when clicking a Button in below fragment. there is a email column in parse database . when clicking the button it should lead to email client with that particular email id of this single item view .

我尝试了一些代码,它不起作用任何人请帮忙??

import android.content.*;
import android.graphics.*;
import android.net.*;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.*;
import android.view.View;
import android.widget.*;

import com.parse.*;
import com.parse.ParseException;
import com.squareup.picasso.*;

import java.io.*;
import java.net.*;

public class SingleItemView extends AppCompatActivity {

    String objectId;
    protected TextView txtv;
    protected TextView txtv1;
    protected ImageView txtv2;
    protected ImageView txtv3;
    Button sendEmail;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_single_item_view);

        txtv =(TextView)findViewById(R.id.txt123);
        txtv1 =(TextView)findViewById(R.id.txt1234);
        txtv2 =(ImageView)findViewById(R.id.txt12345);
        txtv3 =(ImageView)findViewById(R.id.txt123456);
        Intent i =getIntent();
        objectId = i.getStringExtra("objectId");
        ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");
        query.getInBackground(objectId, new GetCallback<ParseObject>() {
            public void done(ParseObject object, ParseException e) {
                if (e == null) {
                    String username = object.getString("firstname");
                    txtv.setText(username);
                    String position = object.getString("position");
                    txtv1.setText(position);
                    URL url = null;
                    try {
                        url = new URL("http://izi-dev.fr/fbc/assets/uploads/" + object.getString("image"));

                    } catch (MalformedURLException e1) {
                        e1.printStackTrace();
                    }
                    Bitmap bmp = null;
                    try {
                        bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }

                    txtv2.setImageBitmap(bmp);


                    URL url1 = null;
                    try {
                        url = new URL("http://izi-dev.fr/fbc/assets/uploads/" + object.getString("image"));
                    } catch (MalformedURLException e1) {
                        e1.printStackTrace();
                    }
                    Bitmap bmp1 = null;
                    try {
                        bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                    txtv3.setImageBitmap(bmp);
                } else {
                    // something went wrong
                }

            }
        });




        sendEmail = (Button) findViewById(R.id.button5);
        sendEmail.setOnClickListener((View.OnClickListener) this);
    }



    public void onClick(View v) {


        try{

            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.putExtra(Intent.EXTRA_EMAIL  , "email");
            emailIntent.setType("text/plain"); // <-- HERE
            startActivity(emailIntent); // <-- AND HERE

        }finally {

        }

    }





}

您设置点击监听器的方式有误。

  1. 实现 ClickListener

    public class SingleItemView extends AppCompatActivity implements View.OnClickListener

  2. 设置监听器 sendEmail.setOnClickListener(this);

  3. 使用注释

    @Override public void onClick(View v)

请试试看。

试试这个:

sendEmail.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(view.getId()==R.id.button5){
                Intent i = new Intent(Intent.ACTION_SEND);
                i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ emailAddress });
                i.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
                i.putExtra(android.content.Intent.EXTRA_TEXT, text);
                startActivity(Intent.createChooser(i, "Send email"));
            }

        }
    });

我可能没有正确理解你的问题,我建议你使用以下插件https://github.com/katzer/cordova-plugin-email-composer#examples。基本上,使用此插件,您只需单击一个按钮即可发送 HTML 嵌入的正文。

cordova.plugins.email.open({
to:      'max@mustermann.de',
subject: 'Greetings',
body:    '<h1>Nice greetings from Leipzig</h1>',
isHtml:  true
});

请查看文档以获取更多信息。希望对你有帮助。