androidstudio 连接打印机
来源:互联网 发布:阿里云域名无法使用 编辑:程序博客网 时间:2024/05/16 18:53
我这里连接的是打印机,不是小票机,大家看清楚了,目前我连接的是Hp 1112这个是可以的。
首先 要下载hp的插件,android设备和打印机相连,android4.4以后,当然也可以修改底层,这个我不会,所以在只能在表层做一点,下载hp插件:Hp Print Service插件(这个在360手机助手里面有)下载安装就可以在设置里面的打印看到HP Inc. 就是它了。就不管了,进行下面操作。
打印三种:webview,bitmap,自定义。你自己看了webview和bitmap都是十分简单的,几句话就ok,但是自定义这个就比较麻烦。是不是在想自定义可以把view转换成bitmap。代码:
private Bitmap getViewBitmap(View v) {
v.clearFocus();
v.setPressed(false);
boolean willNotCache = v.willNotCacheDrawing();
v.setWillNotCacheDrawing(false);
// Reset the drawing cache background color to fully transparent
// for the duration of this operation
int color = v.getDrawingCacheBackgroundColor();
v.setDrawingCacheBackgroundColor(0);
if (color != 0) {
v.destroyDrawingCache();
}
v.buildDrawingCache();
Bitmap cacheBitmap = v.getDrawingCache();
if (cacheBitmap == null) {
Log.e("Folder", "failed getViewBitmap(" + v + ")", new RuntimeException());
return null;
}
Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
// Restore the view
v.destroyDrawingCache();
v.setWillNotCacheDrawing(willNotCache);
v.setDrawingCacheBackgroundColor(color);
return bitmap;
}
这里有问题就是:如果背景是有颜色的就十分耗墨,节约成本的原则上是自定义最好 想打印什么就打印什么,当然你可以选择黑白的。
打印bitmap:
PrintHelper printHelper = new PrintHelper(this);
Bitmap bitmap = ((BitmapDrawable) mImageView.getDrawable()).getBitmap();
printHelper.printBitmap("Print Bitmap", bitmap);
打印webview:
PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
printManager.print("Print webview",mWebView.createPrintDocumentAdapter(), null);
自定义这个我就不说了,比较麻烦。我给代码http://download.csdn.net/detail/u012254541/9884352 。
运行时候就会出现HP的插件,就ok了。
- androidstudio 连接打印机
- 打印机连接
- 【AndroidStudio】AndroidStudio如何连接手机
- API连接打印机
- 打印控制:连接打印机
- 无法连接共享打印机
- 如何连接网络打印机
- 怎样连接网络打印机
- linux 连接windows打印机
- 电脑连接打印机
- android连接打印机
- 局域网如何连接打印机
- Andorid连接USB打印机
- 批处理连接网络打印机
- hp打印机的连接
- 桌面连接配置打印机
- iOS 如何连接打印机
- android 连接网络打印机
- Adreno GPU Profiler工具使用总结
- ajax、json
- MySQL操作详解
- Linux ls 命令
- AdrenoProfiler对opengles的性能分析
- androidstudio 连接打印机
- 图解CommonJS、AMD、CMD规范
- ufw 端口
- Maven
- 新版支付宝开放平台 手机网页支付 整个流程
- 使用Adreno Profiler分析android游戏
- 常用的git指令
- 《Python数据分析与挖掘实战》上机实验1—电力窃漏电用户自动识别
- PrestoException:Error{message='Duplicate entry '2017-01-01' for key date异常解决记录