【问题标题】:Custom mime type ignored in GMail appGMail 应用程序中忽略了自定义 mime 类型
【发布时间】:2012-12-01 23:25:15
【问题描述】:

我正在尝试使用意图在 android 中发送文件。我启动了一个意图选择器并选择了 GMail 应用程序。问题是我无法设置我的自定义 mime 类型,它总是变成 application/octet-stream。

在旧版本的 GMail 应用程序中(或者可能是旧版本的 Android,如 JB 之前的版本?)它可以像这样工作:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Add attributes to the intent
sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Send my file");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(path));
sendIntent.setType("application/vnd.mycustommimetype");
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.lblShare)));

有人知道如何设置 MIME 类型以与更高版本的 GMail/Android 一起使用吗?

经过反复试验,我发现在 GMail 应用程序版本 4 中这工作得很好,但在 GMail 版本 4.2 中,无法设置 mime 类型或以其他方式完成。有谁知道怎么做? :/

【问题讨论】:

  • 我也有同样的问题。你找到解决办法了吗?
  • 在 Android 5.0 中仍然存在问题

标签: android gmail mime-types


【解决方案1】:

很遗憾,您无能为力。天知道是什么原因,一些电子邮件应用程序错误地将自定义文件的 mime 类型设置为八位字节流。 最好的办法是设置您的自定义 mime 类型,但随后,在接收端,请确保您也接受八位字节流。然后,您需要检查文件扩展名以确保它确实是您的文件,而不是其他文件,不适用于您的应用程序(我假设您也在使用自定义扩展名)。

【讨论】:

    【解决方案2】:

    请检查此代码sn-p

    final Intent emailIntent = new Intent(Intent.ACTION_SEND); 
    emailIntent.setType("text/plain"); 
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"webmaster@website.com"}); 
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "my subject"); 
    emailIntent.putExtra(Intent.EXTRA_TEXT, "body text"); 
    context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    

    【讨论】:

    • 问题是这个例子没有显示如何添加自定义mime类型的附件,它只会发送纯文本电子邮件。
    猜你喜欢
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    • 2012-04-30
    • 2020-09-27
    • 1970-01-01
    相关资源
    最近更新 更多