【问题标题】:Android - How to send a table in emailAndroid - 如何在电子邮件中发送表格
【发布时间】:2016-09-03 16:22:37
【问题描述】:

我想通过电子邮件将表格发送到特定的邮件ID,并且我想从phpmysql中检索数据作为表格格式

我对将表格发送到邮件一无所知。我已经尝试过这些链接,请您发送一些不同的链接:

  • android - 如何在电子邮件客户端的电子邮件正文中将文本格式化为表格

  • 在电子邮件意图 android 中嵌入 html 表格标签 - 代码日志

  • 如何在 android 应用程序的电子邮件中发送 Html 表 - 代码日志

  • 在android中使用等发送html邮件——真的没有相对内置的Intent方式吗?

【问题讨论】:

  • 请查看当前答案。对你有帮助stackoverflow.com/a/11448730/2685996
  • 谢谢...如何发送表格格式???
  • 使用html表格格式。那种
    看低谷tutorialspoint.com/html/html_tables.htm
  • 但是邮件中不支持这个表格标签
  • 对不起,现在似乎所有的电子邮件客户端都对 HTML 内容很严格。尝试从答案中解决,请告诉它是否有效。

标签: android html android-studio


【解决方案1】:

试试下面的代码: 注意:您只能将 html 作为附件发送(不能作为电子邮件内容)

private void shareFile(String subject,String body,String fileContent) {
    Intent share = new Intent(android.content.Intent.ACTION_SEND);
    share.setType("text/html");
    share.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);

    // Add data to the intent, the receiving app will decide
    // what to do with it.
    File tempFile ;
    try {
        File sdCard = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
        File tempDir = new File (sdCard.getAbsolutePath() + "/temp-sample");

        AppWebViewClient.deleteDirectoryFiles(tempDir); //delete temp files
        tempDir.mkdirs();
        tempFile = File.createTempFile("sample-records", ".html", tempDir);
        FileOutputStream fout = new FileOutputStream(tempFile);
        tempDir.setReadable(true, false);
        tempFile.setReadable(true, false);
        Uri uri = Uri.fromFile(tempFile.getAbsoluteFile());
        share.putExtra(Intent.EXTRA_STREAM, uri);
        fout.write(fileContent.getBytes());
        fout.close();
    } catch (IOException e) {
        e.printStackTrace();
    }       
    share.putExtra(Intent.EXTRA_SUBJECT, subject);
    share.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(new StringBuilder().append(body).toString()));
    // share.putExtra(Intent.EXTRA_TEXT, body);

    context.startActivity(Intent.createChooser(share, "Share Records!"));
}

【讨论】:

  • 老实说这是事实,因为其他的都行不通。谢谢!
猜你喜欢
  • 1970-01-01
  • 2014-02-01
  • 2014-09-14
  • 1970-01-01
  • 1970-01-01
  • 2012-02-22
  • 2023-03-24
  • 1970-01-01
  • 2023-03-27
相关资源
最近更新 更多