简体   繁体   中英

Android - Send html file to print app via intent, won't appear as html

I have an app I've been working on that has a feature that sends an html file to an app to print it (the app in question is Brother iPrint&Scan).

The code to do this is as follows

    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

    emailIntent.setType("text/html");

    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Printable Stuff");

    // Send attachment (the html file).
    Uri uri = Uri.fromFile(htmlFile);
    emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri);

    startActivity(Intent.createChooser(emailIntent, "Send To"));

What this does is brings up a compatible chooser. Typically, this is gmail and the brother iPrint&Scan app. Gmail will take it as an attachment, and I can send it off and it appears fine. I can view it in a browser, the html markup looks fine (and validates).

Now heres the catch... the brother iPrint&Scan app will take the html file, but it just shows the html as text ... odd. It won't render it at all.

Whats even more disturbing is that I can share a page from my browser to the app and it will display fine (so surely it can read and parse html?)

Am I doing something wrong here?

I've also tried:

emailIntent.setDataAndType(Uri.fromFile(htmlFile), "text/html");

Instead of the putting the extra in the intent... but then the brother print app won't appear in the list at all (gmail does).

Any ideas?

Figured it out.

I wasn't doing anything wrong programatically on my end, but it just so happens that the brother app doesn't read html. It takes in a URL to a webpage, and takes an image capture of it for a print preview.

My solution here is to take my html file, and rather than sending it directly to the brother app I am to upload it to a web hosting service and send the URL to the page to the brother print app in the intent.

If only they had documentation explaining this :|

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