0

I wish that clicking on a preference you may be directed towards a service to send emails such as gmail. Here is what I did

Preference email;
email = (Preference) this.findPreference("email");
email.setOnPreferenceClickListener(new OnPreferenceClickListener()); {
 Intent emailIntent = new Intent( android.content.Intent.ACTION_SEND);
 String[] recipients = new String[]{"" , "[email protected]" ,};
 emailIntent.putExtra( android.content.Intent.EXTRA_EMAIL, recipients);
 emailIntent.putExtra( android.content.Intent.EXTRA_SUBJECT, "This is my text" );
 emailIntent.putExtra( android.content.Intent.EXTRA_TEXT, "");
 emailIntent.setType("message/rfc822");
 startActivity( Intent.createChooser(emailIntent, "Send Email" ));
 }
}
}

I receive error in this line:

 email.setOnPreferenceClickListener(new OnPreferenceClickListener()); {

Why? How can i fix it? Thanks a lot

Android Developer
9871 gold badge8 silver badges22 bronze badges
asked Jul 5, 2013 at 5:05
1
  • And what is the error? Commented Jul 5, 2013 at 5:06

2 Answers 2

3

Most likely it's compile error because your syntax is wrong, use following:

 email.setOnPreferenceClickListener(new OnPreferenceClickListener() {
 @Override
 public boolean onPreferenceClick(Preference preference) {
 // TODO Handle stuff here
 return false;
 }
 });
answered Jul 5, 2013 at 5:10
Sign up to request clarification or add additional context in comments.

Comments

2

You have a syntax error, change to:

email.setOnPreferenceClickListener(new OnPreferenceClickListener() {
 @Override
 public boolean onPreferenceClick(Preference preference) {
 Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
 String[] recipients = new String[]{"" , "[email protected]"};
 emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
 emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "This is my text" );
 emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
 emailIntent.setType("message/rfc822");
 startActivity(Intent.createChooser(emailIntent, "Send Email"));
 }
});

EDIT: forgot the method..

answered Jul 5, 2013 at 5:10

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.