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[]{"" , "MY-EMAIL@gmail.com" ,};
     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

4

2 回答 2

2

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;
        }
    });
于 2013-07-05T05:10:25.047 回答
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[]{"" , "MY-EMAIL@gmail.com"};
        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..

于 2013-07-05T05:10:38.877 回答