1

I am looking for viable ways to send a file from my android app to another android device that doesnt have my app installed.

Option 1. Via share intent: https://stackoverflow.com/a/16755810/1865583

 Intent sharingIntent = new Intent(Intent.ACTION_SEND);
 Uri screenshotUri = Uri.parse(picURI);

 sharingIntent.setType("image/*");
 sharingIntent.setPackage("com.android.bluetooth");
 sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
 startActivity(Intent.createChooser(sharingIntent, "Share image"));

Issue regarding option 1: I would love if i could specify the device i want to send this file to, in the intent parameters? I've searched online but cant find this option.

I've stumbled across this multiple times but it only works on particular devices as far people claim. https://evilzone.org/java/%28android%29-three-ways-to-send-data-over-bluetooth/

ContentValues values = new ContentValues();
String address = device.getAddress();
values.put(BluetoothShare.URI, Uri.fromFile(new File("somefile.mp3")).toString());
values.put(BluetoothShare.DESTINATION, address);
values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
Long ts = System.currentTimeMillis();
values.put(BluetoothShare.TIMESTAMP, ts);
Uri contentUri = getContentResolver().insert(BluetoothShare.CONTENT_URI, values);

Is there a working/tested way to specify the device the bluetooth will try to send the file too? (and pair by default if necessary)?


Option 2. Using Bluetooth sockets to control the file transfer :

I am actually quite interested in developing this options, but all the examples online go about sending files from client to server where both code bases are developed by me.

What i need is to connect via bluetooth to the other android bluetooth enabled device and initiate the file transfer? But i am unsure how to initiate this transfer or which protocols are used if any etc? How would you connect to the default bluetooth app to send it a file?

I've found some information that i thought using as starting point https://stackoverflow.com/a/17237945/1865583

The user talks about using 00001106-0000-1000-8000-00805F9B34FB (File transfer service) and starting a RfcommSocket for communication. Would this be the right way to go to communicate with bluetooth android apps for file transfer?

Community
  • 1
  • 1
JanBo
  • 2,925
  • 3
  • 23
  • 32
  • were you able to solve this issue? – Red M Jan 24 '18 at 20:11
  • Unfortunately no, a change was introduced to our business logic that didnt require this feature...take a look at https://stackoverflow.com/questions/5171248/programmatically-connect-to-paired-bluetooth-device it might point you in the right direction for some kind of viable solution. – JanBo Jan 26 '18 at 11:50

0 Answers0