开发者

Android bluetooth push files

开发者 https://www.devze.com 2023-01-07 00:22 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消