Google Cloud Print
来源:互联网 发布:北欧风 知乎 编辑:程序博客网 时间:2024/06/05 11:41
以下就来分享下学习云打印心得。
为什么要云打印?
所谓的云打印就是使得在任何设备上(台式,手提,手机)的应用程序都能通过云使用任一台自己有使用权的打印机,且该设备无需安装打印驱动。这样的特性使得云打印十分适合在手机上使用。
当前的云打印
GCP,于2011-1-25日推出,至今仍为Beta版。这是唯一一个提供云打印服务的厂商。不过使用条件有两个:一,要有Google账号;二,如果是非云打印机,则要在与打印机相连的PC上装chrome
HP cloud print,其实就是新推出的云打印机ePrint系列,其使用方法十分简单——直接对打印机发邮件。
MotoPrint,摩托罗拉推出的一款在Android手机上进行云打印的应用程序,至今没有发现正式版。
AirPrint,苹果公司推出的内置在ios 4.2系统中的打印服务,只允许在HP的ePrint系列上使用。目前已推出正式版。
在以上四种选择中,GCP是唯一的选择。
PS:在国内不翻GFW就使用GCP,有可能会出现url异常。。。成功概率30%左右
使用GCP
在客户端使用GCP只需三个步骤:一,获取授权码;二,查找可用打印机;三,提交到GCP服务器。由于GCP官网没给出JAVA版的例子,所以在此给个JAVA版的。
获取授权码
提交Google账号和密码给服务器就可以换取授权码
URL url=
new
URL(
"https://www.google.com/accounts/ClientLoginaccountType=HOSTED_OR_GOOGLE&Email="
+
m_sName+
"&Passwd="
+m_sPw+
"&service=cloudprint&source=lin"
);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
BufferedReader reader=
new
BufferedReader(
new
InputStreamReader(connection.getInputStream(),
"US-ASCII"
));
String line;
while
( (line=reader.readLine())!=
null
) {
String[] split=line.split(
"="
);
if
( split.length==
2
&& split[
0
].equals(
"Auth"
) ) {
m_sAuthCode=split[
1
];
//授权码就在这了
}
}
查找可用打印机
将得到的授权码传到指定的HTTP地址就行
URL url=
new
URL(
"http://www.google.com/cloudprint/search?output=json"
);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
connection.setRequestProperty(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
connection.addRequestProperty(
"Authorization"
,
"GoogleLogin auth="
+ m_sAuthCode);
BufferedReader reader=
new
BufferedReader(
new
InputStreamReader(connection.getInputStream(),
"US-ASCII"
));
String line;
while
( (line=reader.readLine())!=
null
) {
SavePrinters(line);
//打印机的信息就存放在line里,写个函数保存吧>_<
}
提交到GCP服务器
将要使用的打印机的ID,打印文件类型,打印的内容与授权码一起POST到指定网址。
URL url=
new
URL(
"https://www.google.com/cloudprint/submit?output=json"
);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
connection.setDoOutput(
true
);
connection.setRequestMethod(
"POST"
);
connection.setRequestProperty(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
connection.addRequestProperty(
"Authorization"
,
"GoogleLogin auth="
+ m_sAuthCode);
String postText=
"printerid="
+ URLEncoder.encode(printerId) +
//上一步得到的打印机ID
"&capabilities="
+ URLEncoder.encode(
""
) +
"&contentType="
+ URLEncoder.encode(
"application/pdf"
) +
//打印类型
"&title="
+ URLEncoder.encode(title) +
"&content="
+GetStringFromPath(path);
//将打印的数据变为String
byte
[] postBytes=postText.getBytes();
connection.getOutputStream().write(postBytes);
connection.getOutputStream().flush();
connection.getOutputStream().close();
至此,就完成作业的提交。而我的打印任务也结束了,YEAH!!!
转自:http://www.cnblogs.com/FengYan/archive/2011/08/01/2122703.html
- Google Cloud Print
- Google cloud computing
- Google Cloud Messaging
- Google秘密武器...雲端運算(Cloud Computing)
- Google Cloud Messaging for Android
- Google Cloud Messaging for Android
- android: Google Cloud Messaging (GCM)
- Google Cloud Messagin for Android
- google cloud messaging(GCM)机制.
- 【转】Google Cloud SQL 发布
- Google Cloud 磁盘满解决办法
- Google Cloud Platform 学习笔记
- Google Cloud Plantform使用备忘
- Google Cloud Messaging(GCM Google云推送)
- Google Cloud Messaging(GCM Google云推送)
- Google Print图书网络搜索测试推出
- Google print相关技术以及下载方法
- Cloud Economics – Amazon, Microsoft, Google Compared
- 折线分割平面
- How to Install Eclipse ADT, Android SDK, and setup AVD Emulator
- 连接数据库成功后,图片获取的问题
- struct device
- 一个简单的鼠标钩子程序
- Google Cloud Print
- HYSBZ-1878-HH的项链
- 去除可执行文件中没用到的符号或函数
- Android setImageResource与setImageBitmap的区别
- Linux华丽入门上场
- MFC 数据库编程 增删改查的一个例子
- 分享40个超棒的CSS3按钮教程
- 圆的直线分割
- mysql 常用操作(整理)