0

here i have make the bluetooth discoverable and listed the pairing of devices in android but i am unable to get how to share the files between 2 devices. please someone help me i am stucked here.

public class MainActivity extends AppCompatActivity {

    private static final int REQUEST_ENABLE_BT = 3;
    private static final int REQUEST_DISCOVERABLE_BT = 300;
    private static final int REQUEST_CONNECT_DEVICE_SECURE = 1;

    private BluetoothAdapter bluetoothAdapter;
    Switch switchAB;
    Toolbar toolbar;
    ProgressDialog mProgressDlg;
    private ArrayList<BluetoothDevice> mDeviceList = new ArrayList<BluetoothDevice>();


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

        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        switchAB = (Switch) findViewById(R.id.switchAB);

        switchAB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {here i have make the bluetooth discoverable and listed the pairing of devices in android but i am unable to get how to share the files between 2 devices.
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ensureDiscoverable();
                } else {
                    disableBluetooth();
                }
            }
        });

        ensureDiscoverable();
            }
        });

        registerReceiver(mReceiver, filter);
    }

}
  • please help me in this – Neelu Agrawal Sep 15 '16 at 06:52
  • You ve managed to set up bluetooth and pair the devices, right? To transfer data you need to implement a server client model using the BluetootheServerSoket/BluetoothSocket classes. Check the example from the sdk. https://developer.android.com/guide/topics/connectivity/bluetooth.html – masp Sep 15 '16 at 07:40
  • yes i have done the searching and pairing of devices but now i am stuck here that how can i share files via bluetooth. – Neelu Agrawal Sep 15 '16 at 09:02
  • The sdk example shows how to send bytes. Is this http://stackoverflow.com/a/6765988/6774854 what you need? – masp Sep 15 '16 at 09:18
  • no i dont want this, i just want to share files or text via bluetooth in my android app – Neelu Agrawal Sep 15 '16 at 09:59
  • The sdk example https://github.com/googlesamples/android-BluetoothChat lets 2 devices exchange text messages via bluetooth, which is what you ask in the comment above. If you want to transfer files also use the previous link I posted to change the code to support files exchange. – masp Sep 15 '16 at 10:47

0 Answers0