1

I am trying to print to an HP DeskJet 450wbt printer from my T-Mobile Pulse Mini phone, using the Android Bluetooth API. The code is as shown below. The connection fails with "Service discovery failed". If I try the alternative method of creating a socket mentioned in a number of other threads, I get "Host is down" instead.

I think that the UUID for BPP is correct, but I am not sure. The printer is a paired device, and it is switched on. I cannot find a USB driver for my phone (a badged Huawei 8110), so I have not been able to debug on the device, or look at a log. I am stuck at this point, and I would be grateful for any advice.

Here is a synopsis of my code:

final String UUID_BPP = "00001122-0000-1000-8000-00805F9B34FB";
final String printerName = "dj450 S/N SG..."; // name of paired printer

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

if (bluetoothAdapter == null) {
    return 2; // phone does not support Bluetooth
}

if (!bluetoothAdapter.isEnabled()) {
    return 3; // Bluetooth has not been enabled
}

Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();

// Loop through paired devices
BluetoothDevice printer = null;

for (BluetoothDevice device : pairedDevices) {
    String s = device.getName();

    if (s.equals(printerName)) {
        printer = device;
        break;
    }
}

if (printer == null)
    return 4; // Paired printer not found

// create socket
UUID BPP = UUID.fromString(UUID_BPP);
BluetoothSocket socket;

try {
    socket = printer.createRfcommSocketToServiceRecord(BPP);
} catch (IOException e) {
    return 5; // Unable to create socket
}
/*
try {
    Method m = printer.getClass().getMethod("createRfcommSocket", 
        new Class[] { int.class });

    socket = (BluetoothSocket) m.invoke(printer, 1);
} catch (Exception e1) {
    return 5; // Unable to create socket
}
*/
try {
    socket.connect(); 
} catch (IOException e) {
    return 6; // Unable to connect socket
}
Philip Sheard
  • 5,789
  • 5
  • 27
  • 42
  • Although I have drawn a blank on this particular issue. I have managed to print to Wi-Fi printers, without using any third party software. – Philip Sheard Aug 18 '11 at 12:52

4 Answers4

2

I think the reason might be that the Bluetooth stack on android you are using might not support the BPP profile , if you are using the standard android versions it does not support BPP.

The mechanism of socket creation is failing because the printer does not implement the SPP profile. The android examples depend on the server side SPP to be listening to be able to connect from the client. The printer for sure will not have generic SPP server listening.

Dennis Mathews
  • 6,897
  • 2
  • 26
  • 39
  • It may well be a question of Android not supporting BPP. I just do not know enough about Android to make a call on that one. Ironically it works just fine on Palm OS, which uses a much simpler paradigm. – Philip Sheard Apr 26 '11 at 06:43
  • Any update on this thread? Does Android support the BPP? If printer won't support SPP, how can we carry out printing task from the phone? – Gopinath Apr 28 '11 at 12:42
  • Android does not support IPP either, but there are a number of paid Android apps that will print to Wi-Fi printers, so I think it is just a question of rolling your own. HP ePrint will work if both devices have an internet connection. – Philip Sheard May 10 '11 at 14:26
  • Philip, you mentioned that the Palm OS uses a much simpler paradigm. Could you elaborate? – Roy Samuel May 26 '11 at 04:56
  • FYI. I was able to print over Bluetooth from a Nokia phone on a bluetooth-dongle-attached printer (Kodak ESP-3 All-in-one printer). – Roy Samuel May 26 '11 at 06:14
  • For Palm OS, I just used the basic serial over Bluetooth, and it worked. Nothing fancy. – Philip Sheard May 27 '11 at 04:11
1

Try this:

Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(device, 1);
Cosmin
  • 21,216
  • 5
  • 45
  • 60
Rajesh
  • 11
  • 1
  • 2
    Thanks for the suggestion. This is the alternative method that I mentioned in my original question. I have already tried it, but it does not seem to work in my case. – Philip Sheard Apr 26 '11 at 06:40
0

There are various bluetooth profiles that maybe used for printing namely, HCRP, BPP, SPP, OPP, DirectPrinting etc. (Ref: http://www.alanjmcf.me.uk/comms/bluetooth/Bluetooth%20Profiles%20and%2032feet.NET.html#_Toc266869878)

Try these other profiles (UUIDs) to try a 'socket.connect'with the printer... Perhaps your Palm OS device would be using another profile than BPP?

By the way Philip, for your printer - HP DeskJet 450wbt, are you using a generic Bluetooth dongle or something you purchased specifically for your printer from HP?

Or does your printer support Bluetooth out of the box, without need to plugin a Bluetooth adapter?

Perhaps you can answer my question here: can generic Bluetooth dongle be used for printers that support printing over Bluetooth?

Let me know how it works out for you.

Community
  • 1
  • 1
Roy Samuel
  • 790
  • 9
  • 24
  • The 450wbt has built-in Bluetooth support. The Palm version did not even use a full UUID - it just set the first two bytes. I strongly suspect that the problem is with Android, where the Bluetooth stack is very limited, – Philip Sheard May 27 '11 at 04:17
  • You are absolutely right. The bluetooth stack implementation currently in Android, does not provide support for Bluetooth Profiles (BPP, HCRP etc). However there is a solution using the “Sybase-iAnywhere-Blue-SDK-for-Android”, which implements the more full-featured Bluetooth Stack for Android, using native code for the underlying Linux kernel of Android. Refer my answer above for links and info regarding this SDK. – Roy Samuel May 27 '11 at 04:33
0

If your phone model (here Android) has built-in support for the Bluetooth Printing Profile, then the phone supports printing to a Bluetooth printer. If you do not see any settings/options on your phone to print (from, for example, the built-in photo gallery applications) to a Bluetooth printer, then in all likelihood the phone does not support Bluetooth printing.

If the support is not built-in, there is little or no chance for you to add the support; it has to come from the device manufacturer(here Android).

(Ref: http://discussion.forum.nokia.com/forum/showthread.php?76295-Bluetooth-printing-option-in-application)


For Bluetooth profile support to be implemented on Android, there is a project called “Sybase-iAnywhere-Blue-SDK-for-Android”, which replaces Android's version, and provides all interfaces into the underlying Bluetooth profiles and protocols. Using this, printing over bluetooth using your Android phone will be possible using the BPP profile provided by this SDK.

See links below for more details: link 1: http://www.sybase.com/detail?id=1064424 Link 2: http://www.sybase.com/products/allproductsa-z/mobiledevicesdks/bluetoothsdks

Roy Samuel
  • 790
  • 9
  • 24