Bluetooth connection on Android Samsung Galaxy XCover always succeeds
===

I have a bit of a problem with Android bluetooth connection. I am using bluetooth for printing on Zebra MZ320 printer. So far I did not have any problems with any of mobile phones (printing worked without any problems on Samsung Galaxy Mini, Samsung Galaxy Ace, Samsung Galaxy Nexus S, Samsung Galaxy S2, Samsung Galaxy Nexus S, Samsung Galaxy Note, HTC Desire Z, HTC Desire S, HTC Desire, HTC Legend, HTC Flyer, Samsung Galaxy Tab), however recently i got Samsung Galaxy XCover where printing does not work.

After a day of researching I made this program:

        
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button bTest = (Button)findViewById(R.id.button1);
        bTest.setOnClickListener( new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (new File("/sdcard/logDat.txt").exists()) {
					new File("/sdcard/logDat.txt").delete();
				}
				
				Toast.makeText(TestPrinterActivity.this, "abcd1234", Toast.LENGTH_SHORT).show();
				String macAddr = "00:22:58:07:BD:A5";
				//sendCpclOverBluetooth(macAddr);
				BluetoothSocket bSocket = null;
				OutputStream outStream = null;
				InputStream inStream = null;
				try {
					log("try... \tMAC address: "+macAddr);
	            	BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddr);
	        	    Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { Integer.TYPE });
	        	    //Method m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] { Integer.TYPE });
	        	    bSocket = (BluetoothSocket)m.invoke(device, new Object[] { Integer.valueOf(1) });
	        	    
	            	//bSocket = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddr).createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
	        	    //bSocket = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddr).createInsecureRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
	        	    
	        	    log("\tconnect()");
	        	    bSocket.connect();
	        	    log("\tgetOutputStream");
	        	    outStream = bSocket.getOutputStream();
	        	    log("\tgetInputStream");
	        	    inStream = bSocket.getInputStream();
	        	    String cpclData = "! U1 SETLP ARI08ITA.CPF 0 20\r\n test123\r\n";
	        	    
	        	    // Send the data to printer as a byte array.
	        	    log("\twriting: "+cpclData);
	        	    outStream.write(cpclData.getBytes());
	        	    log("\tflush");
	        	    outStream.flush();
	        	    Sleeper.sleep(1000);

	        	    log("\tfinish1");
				} catch (Exception e) {
					log("\t\tERROR: "+e.getMessage());
					e.printStackTrace();
					Toast.makeText(TestPrinterActivity.this, "ERROR: "+e.getMessage(), Toast.LENGTH_SHORT).show();
				} finally {
					try {
		        	    log("\tbSocket.close");
						bSocket.close();
		        	    log("\toutStream.close");
						outStream.close();
		        	    log("\tinStream.close");
						inStream.close();
					} catch (Exception e) {
						log("\t\tERROR while closing: "+e.getMessage());
						e.printStackTrace();
						Toast.makeText(TestPrinterActivity.this, "ERROR while closing: "+e.getMessage(), Toast.LENGTH_SHORT).show();
					}
				}
        	    log("endTry");
			}
		});
    }

	private void log(String str) {
    	if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED ) == false)
    		return;
    	
		try {
			BufferedWriter buffWr = new BufferedWriter(new FileWriter("/sdcard/logDat.txt", true));
			buffWr.write(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + ": "+ str);
			buffWr.newLine();
			buffWr.close();
		} catch(Exception e) {
			Toast.makeText(TestPrinterActivity.this, "ERROR writing to log file: "+e, Toast.LENGTH_SHORT).show();
		}
		
	}


Below are CORRECT and WRONG outputs. Each output contains two scenarios (where printer is on and off).
It seems like on Samsung Galaxy XCover bluetooth always succeeds connecting to the printer even when it is offline...
Any suggestions what to do/try would be greatly appreciated.

    	CORRECT output from Samsung Galaxy S3 (4.0.4), Samsung Galaxy Mini (2.3.5), Nexus S
	---------------------------------------------------------------------
	When printer is turned on:
	---------------------------------------------------------------------
	2012-07-25 14:53:36: try... 	MAC address: 00:22:58:07:BD:A5
	2012-07-25 14:53:36: 	connect()
	2012-07-25 14:53:43: 	getOutputStream
	2012-07-25 14:53:43: 	getInputStream
	2012-07-25 14:53:43: 	writing: ! U1 SETLP ARI08ITA.CPF 0 20
	 test123

	2012-07-25 14:53:43: 	flush
	2012-07-25 14:53:44: 	finish1
	2012-07-25 14:53:44: 	bSocket.close
	2012-07-25 14:53:44: 	outStream.close
	2012-07-25 14:53:44: 	inStream.close
	2012-07-25 14:53:44: endTry

	---------------------------------------------------------------------
	When printer is off
	---------------------------------------------------------------------
	2012-07-25 14:53:07: try... 	MAC address: 00:22:58:07:BD:A5
	2012-07-25 14:53:07: 	connect()
	2012-07-25 14:53:12: 		ERROR: Host is down
	2012-07-25 14:53:12: 	bSocket.close
	2012-07-25 14:53:12: 	outStream.close
	2012-07-25 14:53:12: 		ERROR while closing: null
	2012-07-25 14:53:12: endTry



	WRONG output from Samsung Galaxy XCover (2.3.6):
	---------------------------------------------------------------------
	When printer is turned on:
	---------------------------------------------------------------------
	2012-07-25 15:00:48: try... 	MAC address: 00:22:58:07:BD:A5
	2012-07-25 15:00:48: 	connect()
	2012-07-25 15:00:48: 	getOutputStream
	2012-07-25 15:00:48: 	getInputStream
	2012-07-25 15:00:48: 	writing: ! U1 SETLP ARI08ITA.CPF 0 20
	 test123

	2012-07-25 15:00:48: 	flush
	2012-07-25 15:00:49: 	finish1
	2012-07-25 15:00:49: 	bSocket.close
	2012-07-25 15:00:49: 	outStream.close
	2012-07-25 15:00:49: 	inStream.close
	2012-07-25 15:00:49: endTry

	---------------------------------------------------------------------
	When printer is off
	---------------------------------------------------------------------
	2012-07-25 15:01:25: try... 	MAC address: 00:22:58:07:BD:A5
	2012-07-25 15:01:25: 	connect()
	2012-07-25 15:01:25: 	getOutputStream
	2012-07-25 15:01:25: 	getInputStream
	2012-07-25 15:01:25: 	writing: ! U1 SETLP ARI08ITA.CPF 0 20
	 test123

	2012-07-25 15:01:25: 	flush
	2012-07-25 15:01:26: 	finish1
	2012-07-25 15:01:26: 	bSocket.close
	2012-07-25 15:01:26: 	outStream.close
	2012-07-25 15:01:26: 	inStream.close
	2012-07-25 15:01:26: endTry
