0

我创建了这个片段以通过单击我的 android 应用程序的首选项来发送电子邮件。但我想在电子邮件中使用 Build 类将发送电子邮件的电话功能(如手机名称、Android 版本等)放入电子邮件中。我能怎么做?这是我到目前为止所做的。

Preference Email;

Email = (Preference) this.findPreference("email");
Email.setOnPreferenceClickListener(new OnPreferenceClickListener() {
    @Override
    public boolean onPreferenceClick(Preference preference) {
        // Informazioni sul telefono
        String manufacturer = Build.MANUFACTURER;
        String model = Build.MODEL;
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        String[] recipients = new String[]{"" , "EMAIL@gmail.com"};
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "" );
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
        emailIntent.setType("message/rfc822");
        startActivity(Intent.createChooser(emailIntent, "Send Email"));
        return false;
    }
});
4

1 回答 1

0

将您的手机功能数据放入代码中

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, YOUR_PHONE_FEATURES_STRING);

所以你的代码将如下所示:

Preference Email;

Email = (Preference) this.findPreference("email");
Email.setOnPreferenceClickListener(new OnPreferenceClickListener() {
    @Override
    public boolean onPreferenceClick(Preference preference) {
        // Informazioni sul telefono
        String manufacturer = Build.MANUFACTURER;
        String model = Build.MODEL;

        //**EDITED**
        String STR_EMAIL_BODY = "Manufacturer: "+manufacturer + "\nModel: " + model;

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        String[] recipients = new String[]{"" , "EMAIL@gmail.com"};
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "" );
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, STR_EMAIL_BODY);
        //**EDITED**
        intent.setType("text/html");
        startActivity(Intent.createChooser(emailIntent, "Send Email"));
        return false;
    }
});
于 2013-07-05T11:36:50.133 回答