PrinterUtils.java
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package etelligens.com.foodsafety.utils;
import android.content.Context;
import android.print.PrintManager;
import android.print.PrinterCapabilitiesInfo;
import android.print.PrinterId;
import android.print.PrinterInfo;
/**
* @author wj
* @Description: 打印机连接
* @create 2023/12/27 11:52
**/
public class PrinterUtils {
public static void getConnectedPrinters(Context context) {
PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
if (printManager != null) {
PrinterInfo[] printers =null;
for (PrinterInfo printer : printers) {
// 获取打印机信息
PrinterId printerId = printer.getId();
String name = printer.getName();
PrinterCapabilitiesInfo capabilities = printer.getCapabilities();
// 打印连接的打印机信息
System.out.println("Printer ID: " + printerId);
System.out.println("Printer Name: " + name);
// 可以打印更多的打印机信息
// ...
System.out.println(); // 用于分隔不同的打印机信息
}
}
}
}