【问题标题】:Android bluetooth push files安卓蓝牙推送文件
【发布时间】:2012-08-16 22:50:43
【问题描述】:

我想通过蓝牙将文件发送到另一台设备。 我想以编程方式将文件发送到设备。有谁知道如何 我可以通过蓝牙 OPP 发送文件吗?

【问题讨论】:

    标签: android bluetooth


    【解决方案1】:

    你可以试试关注,

    • 第一步在AndroidManifest.xml中添加蓝牙权限

      <uses-permission android:name="android.permission.BLUETOOTH"/>
      <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
      
    • 第 2 步使用以下代码发送文件。

      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);
      
    • 第3步你可以从链接下载BluetoothShare.java

    完成。

    【讨论】:

      猜你喜欢
      • 2012-07-15
      • 2011-08-13
      • 2012-04-02
      • 1970-01-01
      • 2013-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多