简体   繁体   English

通过蓝牙Android传输文件

[英]File transfer over Bluetooth Android

I am using Sample Bluetooth Chat android, its working fine for chatting. 我正在使用示例蓝牙聊天android,它可以正常工作进行聊天。 now i wanted to transfer file using that code. 现在我想使用该代码传输文件。

This is what I'm trying to do : First, the user sends a file name to the server. 这就是我想要做的事情:首先,用户将文件名发送到服务器。 Then, the server sends back that file using that code. 然后,服务器使用该代码发送回该文件。

       ContentValues values = new ContentValues();
       values.put(BluetoothShare.URI, "file:///sdcard/refresh.txt");
       values.put(BluetoothShare.DESTINATION, deviceAddress);
       values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
       Long ts = System.currentTimeMillis();
       values.put(BluetoothShare.TIMESTAMP, ts);
       getContentResolver().insert(BluetoothShare.CONTENT_URI, values);

but i am getting socket errors by doing that. 但是我这样做会收到套接字错误。 Can you suggest me a tutorial or a sample code for android file transfer. 您能为我推荐用于Android文件传输的教程还是示例代码。

For transferring files you can make an explicit call to ACTION_SEND using intents 要传输文件,您可以使用意图明确调用ACTION_SEND

With the ACTION_SEND intent, that will popup a menu with the application that can handle the file type you want to send, from which the user will need to select bluetooth, and then the device. 有了ACTION_SEND意图,将弹出一个菜单,其中包含可以处理您要发送的文件类型的应用程序,用户需要从中选择蓝牙,然后选择设备。

File sourceFile = new File("//mnt/sdcard/TviderFB.apk"); 
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
Intent.setType("image/jpeg"); 
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(sourceFile));
startActivity(intent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM