好吧,我有一个应用程序待命,并且在5到6个月后,Print Manager的一部分停止工作。
这很奇怪,因为加载了PrintDocumentAdapter(在构造函数的生成器中输入,不知道英文的确切名称),但是从不进入onStart,onLayout ...并且不显示任何错误。这是非常无奈的。
电话是:
PrintManager printManager = (PrintManager) this
.getSystemService(Context.PRINT_SERVICE);
String jobName = this.getString(R.string.app_name) + " Document";
printManager.print(jobName, new AlbaranPrintDocumentAdapter(this, this, getResources(), granja, lesiones,
bmFirma, bmSanasVSLesion, bmPorcentajeLesiones, sesion), null);
“打印管理器”类就是这样的(我将示例中的方法的所有内容都剪掉了,但这不是必需的。无论如何,代码永远不会输入到方法中):
package com.example.somename.somename.activities;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.pdf.PdfDocument;
import android.os.Build;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;
import android.print.PageRange;
import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter;
import android.print.PrintDocumentInfo;
import android.print.pdf.PrintedPdfDocument;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.graphics.pdf.PdfDocument.PageInfo;
import com.example.somename.somename.R;
import com.example.somename.somename.pojos.Empresas;
import com.example.somename.somename.pojos.Granja;
import com.example.somename.somename.pojos.Intervencion;
import com.example.somename.somename.pojos.Lesion;
import com.example.somename.somename.pojos.Revision;
import com.example.somename.somename.pojos.Sesion;
import com.example.somename.somename.util.GuardarImagen;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public class AlbaranPrintDocumentAdapter extends PrintDocumentAdapter {
}
public AlbaranPrintDocumentAdapter(E02_GraficasActivity graficasActivity, Context context, Resources res, Granja granja, Lesion[] lesiones, Bitmap bmFirma,
Bitmap bmSanasVSLesion, Bitmap bmPorcentajeLesiones, Sesion sesion) {
Log.v("Lugar", "AlbaranPrintDocumentAdapter");
this.graficasActivity = graficasActivity;
this.context = context;
this.res = res;
this.granja = granja;
this.lesiones = lesiones;
this.bmFirma = bmFirma;
this.bmSanasVSLesion = bmSanasVSLesion;
this.bmPorcentajeLesiones = bmPorcentajeLesiones;
this.sesion = sesion;
}
@Override
public void onStart() {
Log.v("Lugar", "AlbaranPrintDocumentAdapter > OnStart");
}
@Override
public void onLayout(PrintAttributes oldAttributes,
PrintAttributes newAttributes,
CancellationSignal cancellationSignal,
LayoutResultCallback callback,
Bundle metadata) {
Log.v("Lugar", "AlbaranPrintDocumentAdapter > OnLayout");
}
private int calculatePages() {
Log.v("Lugar", "AlbaranPrintDocumentAdapter > calculatePages");
//int count = Math.round(lesiones.length / 7);
//Log.v("ADRI", "calculatePages formula = (" + lesiones.length + " + 10 - 1) / 10");
int count = 0;
if (lesiones.length <= 22) {
count = 1;
} else if (lesiones.length <= 54) {
count = 2;
} else if (lesiones.length <= 86) {
count = 3;
} else if (lesiones.length <= 118) {
count = 4;
} else if (lesiones.length <= 150) {
count = 5;
} else if (lesiones.length <= 182) {
count = 6;
} else if (lesiones.length <= 214) {
count = 7;
} else if (lesiones.length <= 246) {
count = 8;
} else if (lesiones.length <= 278) {
count = 9;
}
return count;
}
@Override
public void onWrite(final PageRange[] pageRanges,
final ParcelFileDescriptor destination,
final CancellationSignal cancellationSignal,
final WriteResultCallback callback) {
Log.v("Lugar", "AlbaranPrintDocumentAdapter > onWrite");
callback.onWriteFinished(pageRanges);
}
private boolean pageInRange(PageRange[] pageRanges, int page) {
Log.v("Lugar", "AlbaranPrintDocumentAdapter > pageInRange");
for (int i = 0; i < pageRanges.length; i++) {
if ((page >= pageRanges[i].getStart()) &&
(page <= pageRanges[i].getEnd()))
return true;
}
return false;
}
private void drawPage(PdfDocument.Page page,
int pagenumber) {
Log.v("Lugar", "AlbaranPrintDocumentAdapter > drawPage");
}
public void calcularTotales() {
}
}