Send file using Android bluetooth?

Is there a way to send files using an internal Bluetooth device to other devices? Give an example.

+7
source share
2 answers

It is strange that Android does not have an explicit OBEX api. Anyway, take a look at this project:


Or alternatively you can use this solution

BluetoothDevice device; String filePath = Environment.getExternalStorageDirectory().toString() + "/file.jpg"; ContentValues values = new ContentValues(); values.put(BluetoothShare.URI, Uri.fromFile(new File(filePath)).toString()); values.put(BluetoothShare.DESTINATION, device.getAddress()); values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND); Long ts = System.currentTimeMillis(); values.put(BluetoothShare.TIMESTAMP, ts); Uri contentUri = getContentResolver().insert(BluetoothShare.CONTENT_URI, values); 

( This class is required)

+2
source

This is a small feature that you can use.

 /** * Method to share data via bluetooth * */ public void bluetoothFunctionality() { String path = Environment.getExternalStorageDirectory() + "/" + Config.FILENAME; File file = new File(path); Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); startActivity(intent); } 

This method sends the file to another device using the default functionality of the Bluetooth device. Before you do this, you must first connect the device, this is a limitation. to send different types of files you just need to change the MIME type in the set type method.

In your manifest file, you must add two permissions, for example

 <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH" /> 
+4
source

All Articles