来自首选项xml的Mailto可能吗?

| 我正在尝试为我的应用程序建立首选项,我希望创建一个“联系开发人员”区域,单击该区域将打开一封发给我的电子邮件。是否可以单独从xml文件执行此操作,还是需要在主类中进行操作? 我在这里搜索了一下,但没有看到关于从XML进行操作的任何信息,所以那不可能吗?以为我会把这个问题扔在那里。 谢谢! 编辑: 这就是我实际上如何将其用于将来寻找某些代码的任何人的方法:
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[]{\"test@gmail.com\"});
        mailto.putExtra(Intent.EXTRA_SUBJECT,\"Subject Here\");
        mailto.putExtra(Intent.EXTRA_TEXT,\"Body Here\");
        startActivity(Intent.createChooser(mailto, \"Select email application.\"));
    return true;
   }
  });

}
}     
已邀请:
        从xml不可能。但是,由于android的工作方式,它的工作量并不大。唯一需要做的就是发送一个意图,通知您要发送电子邮件的系统以及您提供的详细信息。能够做到这一点的应用程序将对此意图做出响应,并为您处理其余的事情。请参阅http://snipplr.com/view/19973/send-email-from-android-using-intent/     
        您可以直接从首选项中进行操作:
<Preference
        android:key=\"contactDevKey\"
        android:title=\"Contact developer\"
        android:summary=\"Tell me all about your problems\">
    <intent android:action=\"android.intent.action.VIEW\"
            android:data=\"@string/contact_developer_uri\"/>
</Preference>
@string/contact_developer_uri
是:
<string name=\"contact_developer_uri\">mailto:my@email.address</string>
限制是没有预定义的主题/身体,使用Java方法以及其他功能是可能的。自4.0 Ice Cream Sandwich以来,支持将ѭ4加到ѭ5中(感谢此提交)。这是允许碎片附加的副作用。因此,您可以提供安德鲁在评论中建议的模板:
<intent android:action=\"android.intent.action.VIEW\"
        android:data=\"@string/contact_developer_uri\">
    <extra android:name=\"android.intent.extra.TEXT\"
           android:value=\"What can I help you with?\" />
    <extra android:name=\"android.intent.extra.SUBJECT\"
           android:value=\"Feedback about World Changing App\" />
</intent>
鼓励使用资源引用,但对于ѭ7和
value
都不必要。 遗憾的是,您不能以这种方式使用
Intent.ACTION_SEND
,因为
EXTRA_EMAIL
必须是
String[]
,而as12ѭ不被支持。     

要回复问题请先登录注册