-1
我使用this教程將我的android應用程序與Google雲打印機集成在一起。它工作正常,但我想這樣做沒有WebViw。Google雲打印無需webview集成
我想有兩個步驟打印:
- 生成PDF文件
- 點擊按鈕 「打印」,並提交打印作業
我分享我的打印機給任何人鏈接,並希望從我的應用程序打印到我的共享打印機的所有PDF文件。
你可以分享一些代碼或教程嗎?
對不起,我的英語
我使用this教程將我的android應用程序與Google雲打印機集成在一起。它工作正常,但我想這樣做沒有WebViw。Google雲打印無需webview集成
我想有兩個步驟打印:
我分享我的打印機給任何人鏈接,並希望從我的應用程序打印到我的共享打印機的所有PDF文件。
你可以分享一些代碼或教程嗎?
對不起,我的英語
我發現this鏈接,它可以幫助我
地址:
@Override
protected Void doInBackground(Void... params) {
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
String user = "[email protected]";
String pass = "password";
String source = "Cloud%20Printing%20Test";
HttpGet authGet = new HttpGet(
"https://www.google.com/accounts/ClientLogin?accountType=HOSTED_OR_GOOGLE&Email="
+ user
+ "&Passwd="
+ pass
+ "&service=cloudprint&source=" + source);
HttpResponse httpResponse;
httpResponse = httpclient.execute(authGet);
String authResponse = EntityUtils
.toString(httpResponse.getEntity());
String authKey = authResponse.substring(authResponse
.indexOf("Auth=") + 5);
authKey = authKey.replace("\n", "");
MyLog.d(TAG, "Auth key: " + authKey);
HttpPost printPost = new HttpPost(
"https://www.google.com/cloudprint/submit?output=json");
printPost.setHeader("Authorization", "GoogleLogin auth=" + authKey);
printPost.setHeader("X-CloudPrint-Proxy", source);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("printerid", "ID"));
nameValuePairs.add(new BasicNameValuePair("title", "TEST"));
nameValuePairs.add(new BasicNameValuePair("capabilities", "{capabilities=[]}"));
nameValuePairs.add(new BasicNameValuePair("content", "123"));
nameValuePairs.add(new BasicNameValuePair("contentType", "text/plain"));
printPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse printResponse = httpclient.execute(printPost);
String lol = EntityUtils.toString(printResponse.getEntity());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
但現在我只能打印文本。如果我找到解決方案如何打印PDF - 我會張貼在這裏的代碼
ADD2:
該代碼發送PDF文件打印
File file = new File("file.pdf");
FileBody fb = new FileBody(file);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addTextBody("printerid", "ID");
builder.addTextBody("title", "TEST2");
builder.addTextBody("capabilities", "{capabilities=[]}");
builder.addTextBody("contentType", "application/pdf");
builder.addPart("content", fb);
printPost.setEntity(builder.build());
如果你downvote,請添加評論爲什麼。我搜索解決方案,但沒有發現,這可以幫助我 – WOLVERINE