locked
Not able to connect to Bluetooth Printer RRS feed

  • Question

  • Hi,

    I was trying to connect to the Bluetooth printer and I am getting "Access denied  error." 

    Please find below code for finding Bluetooth device 

      // look for any paired device

                    PeerFinder.AllowBluetooth = true;

                    // start looking for BT devices

                    PeerFinder.Start();

                    // locate devices that support the serial port profile

                    PeerFinder.AlternateIdentities["Bluetooth:SDP"] = "{00001101-0000-1000-8000-00805F9B34FB}";

                    var available_devices = await PeerFinder.FindAllPeersAsync();

    Then, using below code I was trying to connect and print the text, but it is throwing error. Please find below code. 

      using (StreamSocket ss = new StreamSocket())

                        {

                            await ss.ConnectAsync(pi.HostName, pi.ServiceName);

                            var byes_written = await ss.OutputStream.WriteAsync(System.Text.Encoding.UTF8.GetBytes("this is a test\r\n").AsBuffer());

                        }

    Note: I am using VS 2013, Windows Phone 8.1 blank application and testing on Lumia 630/920. 

    Could you please help me to solve this problem. 



    -Onkarraj



    • Edited by Onkarraj Monday, February 2, 2015 9:34 AM Information added
    Monday, February 2, 2015 9:30 AM

Answers

All replies

  • Have you paired the phone with the printer using the regular Bluetooth settings in the phone prior to your printing attempt?

    You will also have to declare the Bluetooth Device Capabilities you'll be using in your App, see: https://msdn.microsoft.com/en-us/library/windows/apps/dn263090.aspx

    Monday, February 2, 2015 3:00 PM
  • Thanks for the reply. 

    Yes I have paired printer from Bluetooth settings and i got that paired device in collection(in code).  

    But the problem is i am not able to connect automatically using StreamSocket's ConnectAsync method.

    Note: I have turned on capability  "Proximity" from appxmanifest. 

    Thanks,

    Onkarraj Ambatwar


    -Onkarraj


    • Edited by Onkarraj Tuesday, February 3, 2015 7:29 AM Added information
    Tuesday, February 3, 2015 6:47 AM
  • From the description of documentation, I don’t think Proximity is suitable for your scenario. Because proximity is a great way to create a shared app experience between two instances of your app running on two different devices. See from https://msdn.microsoft.com/en-us/library/windows/apps/hh465215.aspx.

    Thursday, February 12, 2015 7:26 AM