【问题标题】:Why i have an error on sending email from preference.xml ussing intent为什么我使用意图从preference.xml 发送电子邮件时出错
【发布时间】:2017-12-14 15:43:16
【问题描述】:

这是我的preference.xml的一部分。

 <Preference
            android:summary="Write me"
            android:title="Title">
            <intent
                android:action="android.intent.action.VIEW"
                android:data="mailto:support@xxxxx.com"
                />
        </Preference>

当我单击此首选项时,我遇到了崩溃

 android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=mailto:xxxxxx.x@x-xxxxxx.xxx }

我做错了什么?

这是我的首选课程。我读了很多标题,但没有找到答案:

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));
        }
    }
}

【问题讨论】:

    标签: android


    【解决方案1】:

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

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

    问题是因为您的设备没有任何可以打开的应用 方案mailto:或者可以处理邮件。


    如何验证ActivityNotFoundException: No Activity found to handle Intent

    那么在这种情况下,您是直接从布局中打开意图:

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

    因此,作为一个选项,您可以进行预验证以确定您是否可以使用安装在您的 android 设备中的某些应用程序打开电子邮件。

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 1970-01-01
      • 1970-01-01
      • 2014-06-21
      • 2016-02-29
      • 2013-07-14
      相关资源
      最近更新 更多