0

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

在此处输入图像描述

在此处输入图像描述

在尝试了这么多示例文件之后。我发现如果文档的大小小于 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;
}

谷歌打印网址是:

<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>
4

0 回答 0