Commit 4e5c9f23 authored by pengguangpu's avatar pengguangpu

添加内部自带重试逻辑的连接检测

parent 52a50a41
......@@ -67,12 +67,18 @@ public class PrinterManager {
*/
IPrinter printer;
/**
* 内部持有调用者初始化的应用
*/
Context ctx;
/**
* 轮询初始化
*
* @return 是否初始化成功
*/
public boolean init(Context context) {
this.ctx = context;
for (Type type : Type.values()) {
try {
if (printer != null) {
......@@ -138,6 +144,7 @@ public class PrinterManager {
* @return
*/
public boolean init(Context context, Type type) {
this.ctx = context;
if (type == null) {
return false;
}
......@@ -184,4 +191,18 @@ public class PrinterManager {
public boolean isConnected() {
return printer != null;
}
/**
* 自带初始化重试的检测逻辑
*
* @return 如果printer!=null则返回true,否则内部初始化一次再返回初始化结果
*/
public boolean checkIsConnectedWithRetry() {
if (printer != null) {
return true;
} else if (ctx != null) {
return init(ctx);
}
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment