0

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?

karl_
  • 340
  • 1
  • 7
  • 18
  • 3
    I don't know the cloud print API but an [URI](http://en.wikipedia.org/wiki/Uniform_resource_identifier) is something like `http://google.com`, `file:///sdcard/file.txt`, `content://sms/inbox/5` and so on. `Uri.parse` will not work 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. – zapl Apr 18 '12 at 18:45
  • That got it working, would you mind posting this as an answer? – karl_ Apr 18 '12 at 19:27

1 Answers1

2

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.

zapl
  • 63,179
  • 10
  • 123
  • 154