来自SharedPreference的电子邮件地址,用于messageIntent

时间:2013-10-27 10:07:14

标签: java android email android-intent sharedpreferences

我想发送一封包含SharedPreferences电子邮件地址的电子邮件。 用户应在SharedPreferences中键入电子邮件地址,消息意图应使用此地址。

我立即使用此代码发送带有附件和修复地址的电子邮件。 请有人能告诉我新代码吗?

private final void mailNote() {
    Intent messageIntent = new Intent(android.content.Intent.ACTION_SEND); 
    String aEmailList[] = { "Mailadresse@gmx.de" };
    messageIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList); 
    messageIntent.putExtra(Intent.EXTRA_TEXT, "eMail from APP");//eMail Text 
    messageIntent.putExtra(Intent.EXTRA_SUBJECT, "Info"); //Betreff 
    // get the data from the cursor using the column index indicatormessage
    Intent.setType("plain/text"); 
    messageIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/CEDApp/CEDApp_export.txt"));
    startActivity(Intent.createChooser(messageIntent, "Email:")); 
    Intent chooser = Intent.createChooser(messageIntent, "choose an option:");//Überschrift 
    // Send the note 
    startActivity(chooser); 
}

感谢德国的问候, Katsche

4 个答案:

答案 0 :(得分:0)

SharedPreferences settings = null;
settings = PreferenceManager.getDefaultSharedPreferences(this);
eMailAdress = settings.getString("eMailAdress", ""); // Replace eMailAdress with your Pref name

答案 1 :(得分:0)

ich bin Android-Anfängerundhabe das jetzt so umgestellt jedoch funktioniert das nicht,sprich es wird keine eMailadresse aus der SharedPreferencesmitübergeben。

private final void mailNote() { 
Intent messageIntent = new Intent(android.content.Intent.ACTION_SEND); 
messageIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 

SharedPreferences settings = getPreferences(MODE_PRIVATE); 
settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); 
eMailAdress = settings.getString("emailkey", ""); 
messageIntent.putExtra(android.content.Intent.EXTRA_EMAIL, eMailAdress); 

messageIntent.putExtra(Intent.EXTRA_TEXT, "eMail from CED-APP");//eMail Text 
messageIntent.putExtra(Intent.EXTRA_SUBJECT, "CED-Info"); //BetreffmessageIntent.setType("plain/text"); 
messageIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/CEDApp/CEDApp_export.txt"));startActivity(Intent.createChooser(messageIntent, "Email:")); 
Intent chooser = Intent.createChooser(messageIntent, "choose an option:");//Überschrift 
// Send the note 
startActivity(chooser); 
}

答案 2 :(得分:0)

那么,在从SharedPreferences检索数据之前,您还需要将其放在那里:

settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
settings.edit().putString("emailKey", "my@email.com").commit();

答案 3 :(得分:0)

我试图像这样更新我的代码:

private final void mailNote() {
Intent messageIntent = new Intent(android.content.Intent.ACTION_SEND);
messageIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

SharedPreferences settings = getPreferences(MODE_PRIVATE);
settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
settings.edit().putString("emailkey", "my@email.com").commit();

messageIntent.putExtra(android.content.Intent.EXTRA_EMAIL, eMailAdress); //<== ERROR

messageIntent.putExtra(Intent.EXTRA_TEXT, "eMail from CED-APP");//eMail Text
messageIntent.putExtra(Intent.EXTRA_SUBJECT, "CED-Info"); //Betreff
messageIntent.setType("plain/text");
messageIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/CEDApp/CEDApp_export.txt"));
startActivity(Intent.createChooser(messageIntent, "Email:"));
Intent chooser = Intent.createChooser(messageIntent, "choose an option:");//Überschrift
// Send the note
startActivity(chooser);
}

我认为注释中的行:ERROR是问题还是?