发送电子邮件意图在手机上工作但不在Android应用程序中使用平板电脑

时间:2014-11-02 16:44:17

标签: android email android-intent tablet mobile-phones

我试图在我的应用程序中发送意图的电子邮件。它在手机上运行得很好,但它不适用于我的平板电脑。这是邮件意图代码:

mail.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(android.content.Intent.ACTION_SEND);
            intent.setType("text/html");
            List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(intent, 0);

            if (!resInfo.isEmpty()) {
                for (ResolveInfo info : resInfo) {
                    if (info.activityInfo.packageName.toLowerCase().contains("email") || info.activityInfo.name.toLowerCase().contains("email")) {
                        intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"asd@asd.com"});
                        intent.setPackage(info.activityInfo.packageName);
                        startActivity(Intent.createChooser(intent, ""));
                    }
                }
            }
        }
    });

这是我的手机布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
    <Button
        android:id="@+id/mail"
        android:layout_width="150dp"
        android:layout_height="50dp"
        android:layout_marginBottom="100dp"
        android:layout_gravity="center|bottom"
        android:background="@drawable/bakanadanis_button"
        android:gravity="center"
        android:text="Bakana Ulaşın"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@android:color/white"
        android:textSize="14dp" />

600dp平板电脑的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/tab_merkezteskilatibg">
    <Button
        android:id="@+id/mail"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:layout_marginBottom="200dp"
        android:layout_gravity="center|bottom"
        android:background="@drawable/bakanadanis_button"
        android:gravity="center"
        android:text="Bakana Ulaşın"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:clickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:textColor="@android:color/white"
        android:textSize="18dp" />

有人知道问题可能是什么吗?感谢。

1 个答案:

答案 0 :(得分:0)

检查您的平板电脑上是否有一个电子邮件客户端应用程序,它通过了您在各种if条件下测试的所有条件。在每个阶段放置调试日志,看看在尝试启动目标应用程序的过程中你的相处程度。