0

Hello everyone I want to send some data via bluetooth from one device to another device but tthe problem is that second device dont have this application installed so i dont know the uiid so i can not use sockets so how to send via using second device os bluetooth service. Thanks in advance.

android_learner
  • 81
  • 2
  • 10

1 Answers1

1

You can try this method

public void sendFileToDevice(BluetoothDevice device,String path){
        File file = new File(path);

        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.setClassName("com.android.bluetooth", "com.android.bluetooth.opp.BluetoothOppLauncherActivity");
        intent.setType("text/plain");
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        startActivity(intent);
    }
  • can u please tell that how i will perform using socket in remote device using their base bluetooth uiid – android_learner Feb 03 '15 at 20:59
  • For that there is a good documentation in android developers website.http://developer.android.com/guide/topics/connectivity/bluetooth.html –  Feb 03 '15 at 21:03
  • But they have not tell how i get the base bluetooth uiid of remote device? – android_learner Feb 03 '15 at 21:05
  • UUID is not something like you get from the device,You just use generate uuid from online generators like this https://www.uuidgenerator.net/ and use in both the devices –  Feb 03 '15 at 21:08
  • sir but the problem is that if i have to use the socket approach then i sholud have the uiid of remote device bluetooth as i have not installed my app on both devices so it is not possible to use mu own uiid so i have to use the system bluetooth uiid – android_learner Feb 03 '15 at 21:12
  • While using socket approach the one device works as server and other works as client. So the only way i know is installing apllication on both the sides.and I hope the what you system uuid may be some random uuid –  Feb 03 '15 at 21:16
  • But the thing is that if i use your suggested solution then i think it only work for small data transfer for large files it not work? – android_learner Feb 03 '15 at 21:18
  • How mush big file you want to send –  Feb 03 '15 at 21:28
  • around 10 mb and even your code not working for small files even for text. – android_learner Feb 03 '15 at 21:33
  • For me it worked for even 60MB file,What is the error you are getting –  Feb 03 '15 at 21:34
  • i am not getting any error but text transfering not start... i am sending text – android_learner Feb 03 '15 at 21:36
  • Please have a look at this solution http://stackoverflow.com/questions/4921384/how-to-send-file-using-bluetooth-on-android-programatically it may be useful –  Feb 04 '15 at 18:37