How to print image and some data from an android device, using printer (print via bluetooth)?

I am developing one app in which i have to print one receipt, receipt has one logo(static) image view, how can i print this to bluetooth printer? and also i have taken signature by using GestureOverlayView, now i have to print that gesture as well along with logo and some data regarding the receipt.How to print image and some data from an android device, using printer (print via bluetooth)?

and i need to print one arabic string as well. which is shown in the TEXT VIEW. for showing signature i am using image view in my layout. Please check the image, i am attaching the image which i have to print, please give me some idea about printing it.

i can change the format in printing, means i dont have to print data in rectangles, but image alignment is the main issue, how will i get to know about alignment?

How To print picture from android using Bluetooth printer device

I’m working on android Bluetooth devices, I want to create an application that print something’s from android phone via a Bluetooth printer. I have done to code and test printing of text, but I can’t



Print data from android app using bluetooth printer

I am developing an android app for restaurant . I want to print the bill after ordering from my app . I am using Bluetooth printer for the printing task . Any body having experience in printing data u

Print data on Zebra printer from Android via bluetooth

I use Zebra QL320 plus printer. Fonts was loaded from Win7(sys. encoding CP1251). When I send text from Android via bluetooth to printer in russian lng: ! 0 200 200 200 1 ENCODING UTF-8 TEXT 14 0 20 8

How to print image with text from android phone to Bluetooth printer.?

I want to print some text with image which is reside on my android phone to Bluetooth printer but text is successfully printed and image is not printed on paper. I using following code: public class S

Print images via Bluetooth printer Android

Hello i am new in developing Android applications, I need to create an application (Tablet – Samsung 10.1 Android ver 3.1) that will print images via Bluetooth printer (Canon CP800 – SELPHY), i have t

How to print data from Android Tablet to a Bluetooth printer

I am developing an application for Android Tablet,now in my application if i select print option then data should be print in the Bluetooth printer.to achieve this first i want to know how to recogniz

How can I Give Print command from iPhone to printer via bluetooth?

I want to implement such app from which without any external connectivity, I want to print img,text,pdf from my iPhone device to printer. I want to use only bluetooth connection between device and pri

How to convert a string into Image and print that image in a bluetooth printer in Android

In my application when i click print button print will come from the Bluetooth printer, right now i am able to print the data… But suddenly i recognize that this (Zeebra MZ320 printer) doesn’t suppo

Print Image(s) via Paired Bluetooth Printer Canon CP 900, CP 800

I need to connect my app with paired bluetooth devices, that will print images via Bluetooth printer (Canon CP900 & CP800 – SELPHY). And I did not find any Canon Printer Android SDK any help or li

How can I print an image on a Bluetooth printer in Android?

I have to print some data on thermal bluetooth printer, I’m doing with this: String message=abcdef any message 12345; byte[] send; send = message.getBytes(); mService.write(send); It works well for

Answers

I try my best to give the answer before that you can get the solution from already asked questions

you have 3 options for printing from android app

1>SDKs/Libraries: (like starmicronics, it’s limited to few devices)

2>Google Play Apps: (directly calling the intent to thirparty apps)

3>Google cloud print: (recommended. It’s easy to use and integrate into an app) By this we connect any printers like Classic printers, Cloud Print printers.

for using Google print as user perspective user should activate google print service to gmail account, Google cloud print used in many places!

Setting up the google print service:

Blog

how to setup network printer to google cloud print

Google cloud print set up1

Google cloud print set up2

Printing via gchrome

Google cloud printers

Integrating Cloud printers to App:

In Android there no option for Airprint like other platforms, but Google made awesome cloud printing option for that such that any printer can use the print option from mobile devices.

Sample codes:

funcode

Google cloud print code

Try using this one….

public class BluetoothPrint extends Activity {

BluetoothAdapter mBTAdapter;
BluetoothSocket mBTSocket = null;
Dialog dialogProgress;
String BILL, TRANS_ID;
String PRINTER_MAC_ID;
final String ERROR_MESSAGE = "There has been an error in printing the bill.";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {

// BILL = getIntent().getStringExtra("TO_PRINT");
// TRANS_ID = getIntent().getStringExtra("TRANS_ID");

// PRINTER_MAC_ID = getIntent().getStringExtra("MAC_ID");
PRINTER_MAC_ID = "00:1F:B7:02:8F:44";
//PRINTER_MAC_ID = "00:12:F3:0D:A3:E6";
// TRANS_ID="12345678";
BILL = "/nSale Slip No: 12345678" + " " + "04-08-2011/n";
BILL = BILL + "----------------------------------------";
BILL = BILL + "/n/n";
BILL = BILL + "Total Qty:" + " " + "2.0/n";
BILL = BILL + "Total Value:" + " " + "17625.0/n";
BILL = BILL + "-----------------------------------------";

mBTAdapter = BluetoothAdapter.getDefaultAdapter();
dialogProgress = new Dialog(BluetoothPrint.this);

try {
if (mBTAdapter.isDiscovering())
mBTAdapter.cancelDiscovery();
else
mBTAdapter.startDiscovery();
} catch (Exception e) {
Log.e("Class ", "My Exe ", e);
}
System.out.println("BT Searching status :"
+ mBTAdapter.isDiscovering());
if (mBTAdapter == null) {
Toast.makeText(this, "Device has no bluetooth capability",
Toast.LENGTH_LONG).show();
finish();
} else {
if (!mBTAdapter.isEnabled()) {
Intent i = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(i, 0);
}

// Register the BroadcastReceiver
IntentFilter filter = new IntentFilter(
BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter); // Don't forget to
// unregister during
// onDestroy
dialogProgress.setTitle("Finding printer...");
dialogProgress
.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
dialog.dismiss();
setResult(RESULT_CANCELED);
finish();
}
});
dialogProgress.show();

}

} catch (Exception e) {
Log.e("Class ", "My Exe ", e);
}
}

public void printBillToDevice(final String address) {
new Thread(new Runnable() {

public void run() {
runOnUiThread(new Runnable() {

public void run() {
dialogProgress.setTitle("Connecting...");
dialogProgress.show();
}

});

mBTAdapter.cancelDiscovery();

try {
System.out
.println("**************************#****connecting");
BluetoothDevice mdevice = mBTAdapter
.getRemoteDevice(address);
Method m = mdevice.getClass().getMethod(
"createRfcommSocket", new Class[] { int.class });
mBTSocket = (BluetoothSocket) m.invoke(mdevice, 1);

mBTSocket.connect();
OutputStream os = mBTSocket.getOutputStream();
os.flush();

os.write(BILL.getBytes());
System.out.println(BILL);


//mBTSocket.close();
setResult(RESULT_OK);
finish();
} catch (Exception e) {
Log.e("Class ", "My Exe ", e);
//Toast.makeText(BluetoothPrint.this, ERROR_MESSAGE, Toast.LENGTH_SHORT).show();
e.printStackTrace();
setResult(RESULT_CANCELED);
finish();

}

runOnUiThread(new Runnable() {

public void run() {
try {
dialogProgress.dismiss();
} catch (Exception e) {
Log.e("Class ", "My Exe ", e);
}
}

});

}

}).start();
}

@Override
protected void onDestroy() {
Log.i("Dest ", "Checking Ddest");
super.onDestroy();
try {
if(dialogProgress != null)
dialogProgress.dismiss();
if (mBTAdapter != null)
mBTAdapter.cancelDiscovery();
this.unregisterReceiver(mReceiver);
} catch (Exception e) {
Log.e("Class ", "My Exe ", e);
}
}

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {

try {
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
System.out.println("***" + device.getName() + " : "
+ device.getAddress());

if (device.getAddress().equalsIgnoreCase(PRINTER_MAC_ID)) {
mBTAdapter.cancelDiscovery();
dialogProgress.dismiss();
Toast.makeText(BluetoothPrint.this,
device.getName() + " Printing data",
Toast.LENGTH_LONG).show();
printBillToDevice(PRINTER_MAC_ID);
Toast.makeText(BluetoothPrint.this,
device.getName() + " found", Toast.LENGTH_LONG)
.show();
}
}
} catch (Exception e) {
Log.e("Class ", "My Exe ", e);
//Toast.makeText(BluetoothPrint.this, ERROR_MESSAGE, Toast.LENGTH_SHORT).show();

}
}
};

@Override
public void onBackPressed() {
try {
if (mBTAdapter != null)
mBTAdapter.cancelDiscovery();
this.unregisterReceiver(mReceiver);
} catch (Exception e) {
Log.e("Class ", "My Exe ", e);
}
setResult(RESULT_CANCELED);
finish();
}

}

from this link Bluetooth Printer issue in android