如何接受蓝牙接收的文件在Android应用程序? [英] How to accept bluetooth received file in Android application?

查看:136
本文介绍了如何接受蓝牙接收的文件在Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个应用程序的从蓝牙设备接收文件的。

I would like to implement an application to receive a file from a Bluetooth device.

在接收,通知将提高到接受传入文件的请求。

Before receiving, a notification will be raised to accept an incoming file request.

在这里,我想激活接受,并自动下载文件,而不会引发接受对话框,当用户接收来自另一蓝牙第二个文件配对的设备,无需在用户launchs的应用程序通知的干扰。

From there, i would like to activate "accept" and download the file automatically without raising an accept dialog when the user receive a second file from another Bluetooth paired device, without notification disturbance when the user launchs an application.

推荐答案

我开发了一个应用程序,它包括这样的任务,你可以使用<一个href="http://developer.android.com/resources/samples/BluetoothChat/src/com/example/android/BluetoothChat/BluetoothChatService.html"相对=nofollow> BluetoothChat 例子。 您必须设置安全标志设置为false: ` 布尔安全= FALSE;

I developed an app that include this kind of task, and you can use BluetoothChat example. You must set the secure flag to false: ` boolean secure = 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;
    }`

,然后读取缓冲区从InputStream,你可以在ConnectedThread发现:

And then read the buffer from the InputStream that you can find in ConnectedThread:

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;
            }
        }

这篇关于如何接受蓝牙接收的文件在Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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