在某些设备上使用SENDTO发送带有附件的电子邮件不起作用 [英] Sending email with attachment using SENDTO on some devices doesn't work

查看:279
本文介绍了在某些设备上使用SENDTO发送带有附件的电子邮件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

起初,您会想到等等,这个问题是重复的!".继续阅读.

At first you're going to think "Wait, this question is a duplicate!". Read on.

我正在尝试使用Intent ACTION_SENDTO(以电子邮件URI作为数据),以使 just 电子邮件应用程序能够响应.

I'm trying to use the Intent ACTION_SENDTO (with an Email URI as data) in order to have just email apps respond.

(使用ACTION_SEND启动没有数据URI的标准"SEND"选择器,这意味着非电子邮件应用程序(例如Google云端硬盘)也会响应).

(Using ACTION_SEND launches a standard "SEND" chooser with no data URI meaning that non email apps, such as Google Drive, also respond).

我的问题是附件在所有设备上均可与ACTION_SEND一起使用,但是-使用ACTION_SENDTO时,仅某些设备可以正确地附加文件. Nexus 7可以使用,但Samsung Galaxy Tab和Acer Iconia 不可以.

My problem is that the attachment works with ACTION_SEND on all devices, however - when using ACTION_SENDTO only some devices correctly attach the files. Nexus 7 works but Samsung Galaxy Tab and Acer Iconia don't.

您可以在下面并排看到不同的方法:

You can see below the different methods side by side:

    String email    = getActivity().getResources().getString(R.string.supportEmail);
    String subject  = getActivity().getResources().getString(R.string.sFeedback);
    subject         = String.format(subject, 
                      getActivity().getResources().getString(R.string.productName));
    String content  = getActivity().getResources().getString(R.string.whatFeedbackWouldYouLikeToProvide) + "\n\n" + 
                      mMessage.getText().toString();
    File toSend     = new File(outfile);

    if(toSend.exists()) {
        Log.e("Feedback", "File path: " + toSend.getAbsolutePath());

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SENDTO);
        emailIntent.setData(Uri.parse("mailto:" +email));
        emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,   Uri.fromFile(toSend));
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,  subject);               
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,     content);  

    /*  Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setType("message/rfc822");
        emailIntent.putExtra(Intent.EXTRA_EMAIL  , new String[]{email});
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        emailIntent.putExtra(Intent.EXTRA_TEXT   , content);
        emailIntent.putExtra(Intent.EXTRA_STREAM , Uri.fromFile(toSend)); */

        try {
            startActivity(emailIntent);
        } catch (ActivityNotFoundException anfe) {
            Toast.makeText(getActivity(), getResources().getString(R.string.pleaseInstallAnEmailClientInOrderToSendUsFeedback), 8000).show();
        }
    }

您可以看到文件路径似乎不是问题,我在一些日志记录中添加了以下报告:

You can see that the filepaths don't seem to be the problem, I've added in some logging which reports:

三星给:

04-11 11:40:09.953: E/Feedback(6286): File path: /storage/sdcard0/logs.zip

Nexus提供:

04-11 11:38:59.249: E/Feedback(12702): File path: /storage/emulated/0/logs.zip

(均基于getExternalStorageDirectory()来确保跨应用程序访问).

(Both based on getExternalStorageDirectory() to ensure cross application access).

有人知道为什么会有区别吗?

Does anybody know why the difference?

推荐答案

尝试通过ACTION_SENDTO解决活动,但实际上是通过ACTION_SEND发送.

Try to resolve activity via ACTION_SENDTO, but actually sending via ACTION_SEND.

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                    "mailto", "", null));
            intent.putExtra(Intent.EXTRA_SUBJECT, title);
            intent.putExtra(Intent.EXTRA_TEXT, text);
            intent.putExtra(Intent.EXTRA_STREAM, getSnapshotUri(snapshot, context, event));

            List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(intent, 0);
            if (resolveInfos.size() == 0) {
                new AlertDialog.Builder(context)
                        .setMessage(R.string.no_mail_app)
                        .setPositiveButton(R.string.ok, null)
                        .show();
            } else {
                String packageName = resolveInfos.get(0).activityInfo.packageName;
                String name = resolveInfos.get(0).activityInfo.name;

                intent.setAction(Intent.ACTION_SEND);
                intent.setComponent(new ComponentName(packageName, name));

                context.startActivity(intent);
            }

这篇关于在某些设备上使用SENDTO发送带有附件的电子邮件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆