Sadece doccument dosyanızı google bulut baskıya göndermeniz yeterlidir. İşte yazdırmak için kullandığım kod. Doküman harici depoda saklanır ve pdf formatındadır. Tek gereklilik, hem cihaz hem de kablosuz yazıcının aynı ağda olması gerektiğidir. Yazıcı bağlıysa, android cihaz ve yazıcıya bağlı sistem aynı google hesabıyla giriş yapmalıdır.
PrintManager printManager = (PrintManager) Order_Bag.this.getSystemService(Context.PRINT_SERVICE);
String jobName = Order_Bag.this.getString(R.string.app_name) + " Document";
//printManager.print(jobName, pda, null);
pda = new PrintDocumentAdapter(){
@Override
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback){
InputStream input = null;
OutputStream output = null;
try {
input = new FileInputStream(Environment.getExternalStorageDirectory() + "/hello.pdf");
output = new FileOutputStream(destination.getFileDescriptor());
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
callback.onWriteFinished(new PageRange[]{PageRange.ALL_PAGES});
} catch (FileNotFoundException ee){
//Catch exception
} catch (Exception e) {
//Catch exception
} finally {
try {
input.close();
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras){
if (cancellationSignal.isCanceled()) {
callback.onLayoutCancelled();
return;
}
// int pages = computePageCount(newAttributes);
PrintDocumentInfo pdi = new PrintDocumentInfo.Builder("The invoice").setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT).build();
callback.onLayoutFinished(pdi, true);
}
};
printManager.print(jobName, pda, null);
Bluetooth yazıcı kullanıyor musunuz ??? – Sujit
Zaten bluetooth yazıcılara yazan bir uygulama yazdım. Bu durumda telefonu sadece cihazla eşleştirmeniz gerekir ve bundan sonra sadece bir soket açar ve ona veri yazarsınız. –
@sujit Bir ağ yazıcısı kullanıyorum – Harinder