Web page to Uri?
-
01-06-2021 - |
Вопрос
I'm working on getting Google Cloud Print into my Android app, but I don't quite get Uri's and MimeTypes, making it difficult for me to figure out where I'm going wrong. I want to print an array of strings containing Html/Css/Javascript. Here is my current code:
public void printScore(String[] pages) {
Uri docUri = Uri.parse("<html><head><title>Hello</title></head><body>Hello, Printer!</body></html>");
// for(int i = 0; i < pages.length; i++ ) {
// docUri = Uri.parse("<html><head><title>Hello</title></head><body>Hello, Printer!</body></html>");
// }
String docMimeType = "text/html";
String docTitle = "My Web Pages";
Intent printIntent = new Intent(this, PrintDialogActivity.class);
printIntent.setDataAndType(docUri, docMimeType);
printIntent.putExtra("title", docTitle);
startActivity(printIntent);
}
This isn't working at all. I get Google Cloud Print saying 'Document Missing'. Where am I going wrong?
Решение
I don't know the cloud print API but an URI is something like http://google.com
, file:///sdcard/file.txt
, content://sms/inbox/5
and so on.
Uri.parse
will not work (or produce meaningful results) unless you put in a Uri as a String in there. Mimetype seems to be ok.
My guess is that you should save the Strings into a file and use Uri.fromFile(thefile)
as docUri
.