简体   繁体   中英

Android - How to send a table in email

I want to send a table to a particular mail id via email, and I want to retrieve the data from phpmysql as a table format

I am not getting any idea about sending table to mail. I have tried these links already, please could you send some different links:

  • android - How to format the text as table in email body of email client

  • Embed html table tag in email intent android - Stack Overflow

  • How to send Html Table in Email in android Application - Stack Overflow

  • Sending html email in android using , etc. - is there really no relatively built-in Intent way?

try out below code: Note : You can only send html as attachment (not as email content)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM