我想实现一个应用程序从蓝牙设备接收文件.
在接收之前,将发出通知以接受传入的文件请求。
从那里,我想激活“接受”并自动下载文件,当用户从另一个蓝牙配对设备接收第二个文件时,不会引发接受对话框,并且当用户启动应用程序时不会出现通知干扰。
我开发了一个包含此类任务的应用程序,您可以使用蓝牙聊天 http://developer.android.com/resources/samples/BluetoothChat/src/com/example/android/BluetoothChat/BluetoothChatService.html例子。
您必须将安全标志设置为 false:
`
布尔安全 = false;
try {
if (secure) {
tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,
MY_UUID_SECURE);
} else {
tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(
NAME_INSECURE, MY_UUID_INSECURE);
}
} catch (IOException e) {
Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
mmServerSocket = tmp;
}`
然后从 ConnectedThread 中的 InputStream 中读取缓冲区:
while (true) {
try {
bytes = mmInStream.read(buffer);
/*write bytes in a file*/
} catch (IOException e) {
Log.e(TAG, "disconnected", e);
connectionLost();
BluetoothChatService.this.start();
break;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)