Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I'm trying to write the C++ code in order to transfer a text file from Desktop to phone via Bluetooth given the device paired.

    Windows::Devices::Enumeration::DeviceInformationCollection services{
        co_await Windows::Devices::Enumeration::DeviceInformation::FindAllAsync(
            Windows::Devices::Bluetooth::Rfcomm::RfcommDeviceService::GetDeviceSelector(
                Windows::Devices::Bluetooth::Rfcomm::RfcommServiceId::ObexObjectPush())) };
    //if (services.Size() > 0)
    {
        // Initialize the target Bluetooth BR device.
        Windows::Devices::Bluetooth::Rfcomm::RfcommDeviceService service{
            co_await Windows::Devices::Bluetooth::Rfcomm::RfcommDeviceService::FromIdAsync(services.GetAt(0).Id()) };
       
        // Check that the service meets this App's minimum
        // requirement
      //  if (SupportsProtection(service)
           // && co_await IsCompatibleVersion(service))
        {
            printf("Connection name \n");
            m_service = service;

            printf("Connection name %ls \n", m_service.ConnectionHostName().DisplayName().c_str());
            printf("Service name %ls \n ", m_service.ConnectionServiceName().c_str());
            printf("Current Status %d \n ", m_service.DeviceAccessInformation().CurrentStatus());
           
            // Create a socket and connect to the target
            co_await m_socket.ConnectAsync(
                m_service.ConnectionHostName(),
                m_service.ConnectionServiceName(),
                Windows::Networking::Sockets::SocketProtectionLevel::BluetoothEncryptionAllowNullAuthentication);
//Socket Progam
// I'm able to create a socket but not getting how to transfer file from PC to phone 
// should I need to write on android phone also to fetch the details.


Now socket is connected to an android device I want to transfer the file using Socket API can anyone please help me to transfer the file via Bluetooth in windows.
Thank you in advance :)

What I have tried:

I'm able to get the details of the Bluetooth connected device but not able to transfer the file.
Posted
Updated 15-Dec-21 0:53am
v5
Comments
Richard MacCutchan 14-Dec-21 4:13am    
There is a secret error in your secret code.
Priyanka S Jigalur 14-Dec-21 4:16am    
can you please brief it
Richard MacCutchan 14-Dec-21 4:56am    
Brief what? We have no idea what your code is doing or what problems you are facing.
Priyanka S Jigalur 15-Dec-21 6:10am    
can you help now
Richard MacCutchan 15-Dec-21 6:49am    
With what? We have no idea what the problem is in your code. Please use the Improve question link above, and add complete details of what is not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900