简体   繁体   English

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

[英]Direct to android-mail client when clicking a button

hi, 你好

this is a single Item View of a ListView. 这是ListView的单个Item View。 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 . 当单击按钮时,它应使用该单个项目视图的特定电子邮件ID引导电子邮件客户端。

I tried some code its not working anyone please help ?? 我尝试了一些代码不起作用的任何人请帮助??

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 {

        }

    }





}

You have set the click listener in wrong way. 您将点击侦听器设置为错误的方式。

  1. Implement the ClickListener 实现ClickListener

    public class SingleItemView extends AppCompatActivity implements View.OnClickListener

  2. Set the listener sendEmail.setOnClickListener(this); 设置侦听器sendEmail.setOnClickListener(this);

  3. Use annotations 使用注释

    @Override public void onClick(View v)

Please try that. 请尝试一下。

Try this: 尝试这个:

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

        }
    });

As i may understood correctly your problem, I suggest you to use the following plugin https://github.com/katzer/cordova-plugin-email-composer#examples . 据我可能正确理解您的问题,我建议您使用以下插件https://github.com/katzer/cordova-plugin-email-composer#examples Basically with this plugin you can send HTML embodeed body with the click of a button. 基本上,使用此插件,您只需单击按钮即可发送HTML嵌入的正文。

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

Please check the documentation for further info. 请检查文档以获取更多信息。 I hope i helped you. 我希望我能帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM