我从pax设备打印自定义报告但不起作用。首先我在Web视图上加载自定义报告URL,然后单击打印按钮。打印不是来自pax设备。问题是第一次打印来自设备但不是第二次。检查我下面的代码 首先,我加载所有库
> if (Appconstant.sharedPreferences == null) {
Appconstant.sharedPreferences = getApplicationContext().getSharedPreferences(
"Pref", 0);
}
String loadLib = Appconstant.sharedPreferences.getString("loadLib", "");
Log.e(TAG,"loadLib==>"+loadLib);
Toast.makeText(PrintActivity.this, "load lib==>"+loadLib, Toast.LENGTH_SHORT).show();
if(loadLib.isEmpty()){
System.loadLibrary("F_DEVICE_LIB_Android");
System.loadLibrary("F_PUBLIC_LIB_Android");
System.loadLibrary("JniEntry_V1.00.00_20170616");
System.loadLibrary("JniMC_V1.00.00_20170616");
System.loadLibrary("JniWave_V1.00.00_20170616");
System.loadLibrary("F_ENTRY_LIB_Android");
System.loadLibrary("F_MC_LIB_Android");
System.loadLibrary("F_WAVE_LIB_Android");
System.loadLibrary("JniEMV_V1.00.00_20170616");
}
在Web视图上加载自定义报告URL后,单击“打印”按钮。单击“打印”按钮后,我调用Print1方法
private void print1(WebView receipt_webview) {
Bitmap bitmap = getWebViewBitmap(receipt_webview);
IDAL dal = DALProxyClient.getInstance().getDal(PrintActivity.this);
dal.getPrinter().init();
dal.getPrinter().printBitmapWithMonoThreshold(bitmap, 230);
dal.getPrinter().step(200);
dal.getPrinter().start();
}
getWebViewBitMap方法,请检查以下代码
private static Bitmap getWebViewBitmap(View view) {
Log.e(TAG,"PrintActivity2"+view);
Bitmap bitmap = null;
// width measure spec
int widthSpec = View.MeasureSpec.makeMeasureSpec(view.getMeasuredWidth(), View.MeasureSpec.AT_MOST);
// height measure spec
int heightSpec = View.MeasureSpec.makeMeasureSpec(view.getMeasuredHeight(), View.MeasureSpec.AT_MOST);
// measure the view
view.measure(widthSpec, heightSpec);
// set the layout sizes
int left = view.getLeft();
int top = view.getTop();
int width = view.getMeasuredWidth();
int height = view.getMeasuredHeight();
int scrollX = view.getScrollX();
int scrollY = view.getScrollY();
view.layout(left, top, width + left, height + top);
// create the bitmap
bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
// create a canvas used to get the view's image and draw it on the
// bitmap
Canvas c = new Canvas(bitmap);
// position the image inside the canvas
c.translate(-view.getScrollX(), -view.getScrollY());
// get the canvas
view.draw(c);
return bitmap;
}
此代码第一次正常运行,但第二次无法正常工作。请检查代码