Android的蓝牙文件推送 [英] Android bluetooth push files

查看:471
本文介绍了Android的蓝牙文件推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过蓝牙发送文件到另一个设备。
我想文件编程方式发送到设备。有没有人一个想法如何
我可以通过蓝牙OPP发送文件?

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?

推荐答案

您可以尝试以下,


  • 在AndroidManifest.xml步骤1添加Bluetooth许可

  • Step 1 add bluetooth permission in the AndroidManifest.xml

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


  • 步骤2用以下code发送一个文件。

  • 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);
    


  • 步骤3,你可以下载<一个href=\"https://www.$c$caurora.org/git/projects/ag-gb-dsds-7227/repository/revisions/18065ea37751cc6fc3a07430b22f469df8d29339/changes/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothShare.java\"相对=nofollow> BluetoothShare.java 从链接。

    完成的。

    这篇关于Android的蓝牙文件推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆