I have an Android application which can do a Cloud Print by using OAuth2.0 and Google Play Service library. On my side, I will put the content as URL to Cloud Printing and everything is fine. I can get the response Status Code back from Google Cloud as 200 and the response Message is "Document is added in the print queue" But when I check in the Google Print job it show me that job is error like this:
After trying with so many example file. I found out that document will be able to be printed if its size is less than 2 MB and that URL must be the physical file path (I tried with Servlet URL and it isn't working). I couldn't find any site that talk about the maximum file size of Cloud printing, the way to set it or the type of URL content. Do you guys have any suggestion about this if I want to print with Servlet URL or the file which have size more than 2 MB?
Here is my Code:
protected PrintersResult doInBackground(String... params) {
PrintersResult pResult = null;
try {
String contentUrl = "http://ocw.mit.edu/ans7870/resources/Strang/Edited/Calculus/Calculus.pdf";
String url = getString(R.string.google_cloud_print_url,
new Object[] { mToken, printId, contentUrl });
HttpResponse response = NetworkUtil.getCloudPrintResult(url,
mToken);
StatusLine statusLine = response.getStatusLine();
int sc = statusLine.getStatusCode();
if (sc == HttpStatus.SC_OK) {
String responseString = EntityUtils.toString(response
.getEntity());
pResult = new Gson().fromJson(responseString,
PrintersResult.class);
} else
errorMessage = getString(R.string.label_server_return_error_code)
+ String.valueOf(sc);
} catch (ArrayIndexOutOfBoundsException e) {
errorMessage = getString(R.string.label_print_error);
} catch (HttpResponseException e) {
errorMessage = getString(R.string.label_login_gaccount_error_credentials);
} catch (IOException e) {
errorMessage = getString(R.string.label_print_error);
} catch (Exception e) {
errorMessage = e.getMessage();
}
return pResult;
}
public static HttpResponse getCloudPrintResult(String url, String token) {
HttpClient httpclient = NetworkUtil.createHttpsClient();
HttpPost httppost = new HttpPost(url);
HttpResponse response = null;
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("client_id",MPOS_GOOGLE_CLIENT_ID));
nameValuePairs.add(new BasicNameValuePair("access_token", token));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httppost.addHeader("Authorization", "OAuth " + token);
httppost.addHeader("contentType", "application/pdf");
// Execute HTTP Post Request
response = httpclient.execute(httppost);
} catch (Exception e) {
Log.e("ConnectionUtil", e.getMessage(), e);
}
return response;
}
Google print url is:
<string name="google_cloud_print_url" formatted="false">https://www.google.com/cloudprint/submit?access_token=%s&cookies=false&printerid=%s&content=%s&contentType=url</string>