-1

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 .

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 {

        }

    }





}
Faizal Munna
  • 515
  • 5
  • 21
  • Please check this stack [http://stackoverflow.com/questions/5596971/android-open-emailclient-programatically](http://stackoverflow.com/questions/5596971/android-open-emailclient-programatically) – Andreas Constantinou Feb 23 '17 at 07:00
  • @Andreas Constantinou hi thanks I already checked it. but there is no way to connect the button . can you please tell me that how to implement that in my code – Faizal Munna Feb 23 '17 at 07:05

2 Answers2

1

You have set the click listener in wrong way.

  1. Implement the ClickListener

    public class SingleItemView extends AppCompatActivity implements View.OnClickListener

  2. Set the listener sendEmail.setOnClickListener(this);

  3. Use annotations

    @Override public void onClick(View v)

Please try that.

jakubbialkowski
  • 1,546
  • 16
  • 24
  • can you tell how to implement the email column name in the parse database to my code email column name is " email " – Faizal Munna Feb 23 '17 at 07:31
  • hi, @jakubbialkowski . please check this if you can http://stackoverflow.com/questions/42968587/android-email-client-receiver-email-id-empty-in-android-parse – Faizal Munna Mar 23 '17 at 07:39
1

As i may understood correctly your problem, I suggest you to use the following plugin 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.

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.