Android 为什么我在使用preference.xml发送电子邮件时出错

Android 为什么我在使用preference.xml发送电子邮件时出错,android,Android,这是我的preference.xml的一部分 <Preference android:summary="Write me" android:title="Title"> <intent android:action="android.intent.action.VIEW" android:data="mailto:support@xxxxx.

这是我的preference.xml的一部分

 <Preference
            android:summary="Write me"
            android:title="Title">
            <intent
                android:action="android.intent.action.VIEW"
                android:data="mailto:support@xxxxx.com"
                />
        </Preference>
我做错了什么

这是我喜欢的班级。我读了很多广告,但没找到答案:

public class Preferences extends PreferenceActivity  implements SharedPreferences.OnSharedPreferenceChangeListener {
    public static final String KEY_PREF_INSTANT_PRINT = "instantPrinting";
    public static final String KEY_PREF_INSTANT_PRINT_SCREEN = "instantPrintingScreen";
    public static final String KEY_PREF_PAY_BUTTONS = "paymentTypes";

    @Override
    protected void onResume() {
        super.onResume();
        getPreferenceScreen().getSharedPreferences()
                .registerOnSharedPreferenceChangeListener(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        getPreferenceScreen().getSharedPreferences()
                .unregisterOnSharedPreferenceChangeListener(this);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
        addPreferencesFromResource(R.xml.preference);
        Preference instantPrintingScreen = findPreference(KEY_PREF_INSTANT_PRINT_SCREEN);
        instantPrintingScreen.setEnabled(sharedPref.getBoolean(KEY_PREF_INSTANT_PRINT, false));
    }

    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
                                          String key) {
        if (key.equals(KEY_PREF_INSTANT_PRINT)) {
            Preference connectionPref = findPreference(KEY_PREF_INSTANT_PRINT_SCREEN);
            connectionPref.setEnabled(sharedPreferences.getBoolean(key, false));
        }
    }
}

首选项将完美工作,这里的问题是您没有任何客户端应用程序来处理电子邮件

我安装了3个可以处理电子邮件的应用程序,因此如果我尝试打开首选项,我会看到这些应用程序:

问题是因为你的设备没有任何可以打开的应用程序 方案
mailto:
或可以处理电子邮件


如何验证ActivityNotFoundException:未找到可处理意图的活动

在这种情况下,您直接从布局打开,目的是:

<intent
            android:action="android.intent.action.VIEW"
            android:data="mailtoa:support@xxxxx.com"
            />

问题是你的意图,你是否在使用IntentChooser,添加你的代码。我添加了一个类。有什么想法吗?在这种情况下,我如何捕获异常以使我的应用程序不崩溃?
<intent
            android:action="android.intent.action.VIEW"
            android:data="mailtoa:support@xxxxx.com"
            />
public boolean canOpenEmail(){
    try {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:support@xxxxx.com")));
    }catch (ActivityNotFoundException afe){
        Log.e(TAG, afe.getMessage());
        return false;
    }
    return true;
}