Android:打印队列中的Google Cloud Print错误

时间:2014-04-21 07:21:25

标签: android google-cloud-print

我有一个Android应用程序,可以使用OAuth2.0和Google Play服务库进行云打印。在我这边,我会把内容作为URL打印到云打印,一切都很好。我可以将响应状态代码从Google Cloud恢复为 200 ,响应消息“文档已添加到打印队列中”但是当我签入Google Print作业时它告诉我工作是这样的错误:

enter image description here

enter image description here

尝试了这么多示例文件后。我发现如果文档的大小小于2 MB并且该URL必须是物理文件路径(我尝试使用Servlet URL并且它不能正常工作),那么该文档将能够打印出来。我找不到任何关于云打印的最大文件大小,设置方式或URL内容类型的网站。 如果我想用Servlet URL或大小超过2 MB的文件打印,你们对此有什么建议吗?

这是我的代码:

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打印网址为:

<string name="google_cloud_print_url" formatted="false">https://www.google.com/cloudprint/submit?access_token=%s&amp;cookies=false&amp;printerid=%s&amp;content=%s&amp;contentType=url</string>

0 个答案:

没有答案