I am trying to build out the preferences for my application and I was hoping to do a "Contact the developer" area where when clicked, it would open an email directed to me. Is this possible to do from the xml file alone or do I need to do stuff in the main class?
I searched here a bit but did not see anything about doing it from XML so maybe thats not possible? Thought I would throw this question out there.
Thanks!
EDIT: This is how I actually got it to work for anyone in the future looking for some code:
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
public class Prefs extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.prefs);
Preference mailTo = (Preference) findPreference("mailTo");
mailTo.setOnPreferenceClickListener(new OnPreferenceClickListener()
{
public boolean onPreferenceClick(Preference preference)
{
// Preferences
Intent mailto = new Intent(Intent.ACTION_SEND);
mailto.setType("message/rfc822") ; // use from live device
mailto.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
mailto.putExtra(Intent.EXTRA_SUBJECT,"Subject Here");
mailto.putExtra(Intent.EXTRA_TEXT,"Body Here");
startActivity(Intent.createChooser(mailto, "Select email application."));
return true;
}
});
}
}
SEND
action multiple times now, but a lot of apps handle*/*
mime and hence a chooser shows up with totally irrelevant apps (aside the correct GMail and Mail): Skype, Google Drive, Total Commander all want to send emails :( Drive for example creates a file named as value ofEXTRA_SUBJECT
with value ofEXTRA_TEXT
as contents. – Mellette