androidemailandroid-intenttabletmobile-phones

Sending email intent working on phone but not working on tablet in Android application


I'm trying to send email with an intent in my application. It works just fine on mobile phones, but it is not working on my tablet. Here is the mail intent code:

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

And this is my layout for phone:

<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" />

And layout for 600dp tablet:

<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" />

Does anybody know what the issue might be? Thanks.


Solution

  • Check if your tablet has an email client application on it that passes all the conditions you are testing for in your various if conditions. Place debug logs at each stage and see how far you getting along in the process of trying to start your targeted app.