来自偏好xml的Mailto可能吗?

Rob*_*Rob 15 mailto android preferences android-intent

我正在尝试构建我的应用程序的首选项,我希望做一个"联系开发人员"区域,当点击它时,它会打开一个指向我的电子邮件.这可以单独从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;
   }
  });

}
Run Code Online (Sandbox Code Playgroud)

}

rof*_*son 31

您可以直接从首选项中执行此操作:

<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>
Run Code Online (Sandbox Code Playgroud)

在哪里@string/contact_developer_uri:

<string name="contact_developer_uri">mailto:my@email.address</string>
Run Code Online (Sandbox Code Playgroud)

限制是没有预定义的主题/正文,这可能使用Java方法和附加功能.由于此提交,因此 4.0冰淇淋三明治支持添加extras到<intent>s (请参阅提交标记).这是为片段添加额外内容的副作用.因此,您可以在评论中提供安德鲁建议的模板:

<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>
Run Code Online (Sandbox Code Playgroud)

鼓励使用资源引用,但对于s datavalues 都不是必需的.

可悲的是,你不能用Intent.ACTION_SEND这种方式,因为EXTRA_EMAIL需要成为一个String[]并且不支持<extra android:value=.


Wil*_*Kru -1

从 xml 来看这是不可能的。然而,由于 Android 的工作方式,这并不是很多工作。唯一需要做的就是发送一个意图,通知系统您想要发送电子邮件以及您提供的详细信息。能够执行此操作的应用程序将响应此意图并为您处理其余的事情。请参阅http://snipplr.com/view/19973/send-email-from-android-using-intent/