Android bluetooth push files
i want to send files via Bluetooth to a another device开发者_运维知识库. I want to send files to a device programmatically. Has anyone a idea how i can send files via Bluetooth OPP?
You can try following,
Step 1 add bluetooth permission in the AndroidManifest.xml
<uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
Step 2 use following code to send a file.
BluetoothDevice device; String filePath = Environment.getExternalStorageDirectory().toString() + "/data.txt"; 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);
Step 3 you can download BluetoothShare.java from the link.
done.
精彩评论