如何在Android上监听/检测传入的蓝牙文件传输

时间:2018-10-25 13:29:19

标签: android bluetooth

我有一个Android应用程序,它基于BluetoothChat的google示例来管理蓝牙的输入和传输。

它有3个线程,

  • 其中之一就像“连接到”(如客户端模式)。
  • 第二个功能类似于“监听”(例如服务器),它等待/监听设备连接。
  • 第三个是管理交配的人。它使用InputStreamReader和OutoutStreamReader写入和读取通过套接字发送的消息。

    public void run() {
    
        Log.i(TAG, "BEGIN mConnectedThread");
        byte[] buffer = new byte[1024];
        int bytes;
    
        // Keep listening to the InputStream while connected
        while (mState == STATE_CONNECTED) {
            try {
                // Read from the InputStream
                bytes = mmInStream.read(buffer);
    
                // Send the obtained bytes to the UI Activity
                mHandler.obtainMessage(ConstantesBluetooth.MESSAGE_READ, bytes, -1, buffer)
                        .sendToTarget();
            } catch (IOException e) {
                Log.e(TAG, "disconnected", e);
                connectionLost();
                break;
            }
        }
    }
    

在设备之间发送文本和数据确实非常好。

问题是,当共享文件时(例如仅通过蓝牙连接发送文件,例如图像或zip文件),InputStreamReader不会读取该数据,而InputStreamReader一直在读取我所有的消息已经发送了。

我实际看到的功能(我可以在logcat中看到它)是与OPP(对象推送配置文件)相关的一组类管理所有连接和有关它的信息。

但是我无法在Android文档中找到可用的Android蓝牙配置文件中的配置文件,也无法收听使用这种类型的传输时触发的意图。

我不得不说发送文件的设备是Windows笔记本电脑,我不知道他们是怎么做的。

那么,由于该事件必须是系统广播的,所以我该如何监听该事件,或者在将传入文件发送给我时是否还有其他方法可以得到通知? 像这样: Incoming file

我在其中找到OPP服务和侦听器的日志:

10-25 12:51:52.086 26423-28067/? V/[Bluetooth.OPP]BtOppRfcommListener: Accepted connection from 40:9F:38:9C:8A:10
10-25 12:51:52.087 26423-28067/? V/[Bluetooth.OPP]BtOppRfcommListener: Accepting connection...
10-25 12:51:52.088 26423-26423/? D/[Bluetooth.OPP]BtOppService: Get incoming connection
10-25 12:51:52.088 26423-26423/? I/[Bluetooth.OPP]BtOppService: Start Obex Server
10-25 12:51:52.088 26423-26423/? D/[Bluetooth.OPP]BtOppObexServer: Create ServerSession with transport com.android.bluetooth.BluetoothObexTransport@c4d9b2d
10-25 12:51:52.089 26423-26423/? D/[Bluetooth.OPP]BtOppService: Get ServerSession com.android.bluetooth.opp.BluetoothOppObexServerSession@420f862 for incoming connectioncom.android.bluetooth.BluetoothObexTransport@c4d9b2d
10-25 12:51:52.120 26423-3411/? D/[Bluetooth.OPP]BtOppObexServer: onConnect
10-25 12:51:52.120 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: Dumping HeaderSet javax.obex.HeaderSet@b83cdf3
10-25 12:51:52.120 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: COUNT : null
10-25 12:51:52.121 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: NAME : null
10-25 12:51:52.121 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: TYPE : null
10-25 12:51:52.121 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: LENGTH : null
10-25 12:51:52.121 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: TIME_ISO_8601 : null
10-25 12:51:52.121 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: TIME_4_BYTE : null
10-25 12:51:52.121 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: DESCRIPTION : null
10-25 12:51:52.121 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: TARGET : null
10-25 12:51:52.122 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: HTTP : null
10-25 12:51:52.122 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: WHO : null
10-25 12:51:52.122 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: OBJECT_CLASS : null
10-25 12:51:52.122 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: APPLICATION_PARAMETER : null
10-25 12:51:52.122 26423-3411/? V/[Bluetooth.OPP]BtOppObexServer: onConnect(): uuid =null
10-25 12:51:52.122 26423-3411/? D/BluetoothDevice: mAddress: 40:9F:38:9C:8A:10
10-25 12:51:52.123 26423-3411/? V/[Bluetooth.OPP]BluetoothOppManager: isWhitelisted ++, address = 40:9F:38:9C:8A:10
10-25 12:51:52.123 26423-3411/? V/[Bluetooth.OPP]BluetoothOppManager: cleanupWhitelist ++
10-25 12:51:52.123 26423-3411/? V/[Bluetooth.OPP]BluetoothOppManager: isWhitelisted ++, address = 40:9F:38:9C:8A:10
10-25 12:51:52.123 26423-3411/? V/[Bluetooth.OPP]BluetoothOppManager: cleanupWhitelist ++
10-25 12:51:52.463 26423-3411/? D/[Bluetooth.OPP]BtOppObexServer: onPut javax.obex.ServerOperation@cd0eab0
10-25 12:51:52.463 26423-3411/? D/BluetoothDevice: mAddress: 40:9F:38:9C:8A:10
10-25 12:51:52.464 26423-3411/? V/[Bluetooth.OPP]BluetoothOppManager: isWhitelisted ++, address = 40:9F:38:9C:8A:10
10-25 12:51:52.464 26423-3411/? V/[Bluetooth.OPP]BluetoothOppManager: cleanupWhitelist ++
10-25 12:51:52.464 26423-3411/? V/[Bluetooth.OPP]BluetoothOppManager: isWhitelisted ++, address = 40:9F:38:9C:8A:10
10-25 12:51:52.464 26423-3411/? V/[Bluetooth.OPP]BluetoothOppManager: cleanupWhitelist ++
10-25 12:51:52.464 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: Dumping HeaderSet javax.obex.HeaderSet@95bd29
10-25 12:51:52.464 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: COUNT : null
10-25 12:51:52.464 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: NAME : UpdateMandoCar.zip
10-25 12:51:52.464 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: TYPE : null
10-25 12:51:52.464 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: LENGTH : 2801484
10-25 12:51:52.464 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: TIME_ISO_8601 : null
10-25 12:51:52.465 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: TIME_4_BYTE : null
10-25 12:51:52.465 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: DESCRIPTION : null
10-25 12:51:52.465 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: TARGET : null
10-25 12:51:52.465 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: HTTP : null
10-25 12:51:52.465 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: WHO : null
10-25 12:51:52.465 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: OBJECT_CLASS : null
10-25 12:51:52.465 26423-3411/? V/[Bluetooth.OPP]BluetoothOpp: APPLICATION_PARAMETER : null
10-25 12:51:52.465 26423-3411/? V/[Bluetooth.OPP]BtOppObexServer: Mimetype guessed from extension zip is application/zip
10-25 12:51:52.476 26423-26423/? D/ActivityThread: SVC-Calling onStartCommand: com.android.bluetooth.opp.BluetoothOppService@34413b6, flags=0, startId=40
10-25 12:51:52.476 26423-26423/? V/[Bluetooth.OPP]BtOppService: onStartCommand
10-25 12:51:52.477 26423-26423/? D/ActivityThread: SVC-SERVICE_ARGS handled : 0 / ServiceArgsData{token=android.os.BinderProxy@6f17f51 startId=40 args=Intent { cmp=com.android.bluetooth/.opp.BluetoothOppService }}
10-25 12:51:52.482 26423-3412/? V/[Bluetooth.OPP]BtOppService: pendingUpdate is true keepUpdateThread is false sListenStarted is true
10-25 12:51:52.485 26423-26423/? D/ActivityThread: SVC-Calling onStartCommand: com.android.bluetooth.opp.BluetoothOppService@34413b6, flags=0, startId=41
10-25 12:51:52.485 26423-26423/? V/[Bluetooth.OPP]BtOppService: onStartCommand
10-25 12:51:52.485 26423-26423/? D/ActivityThread: SVC-SERVICE_ARGS handled : 0 / ServiceArgsData{token=android.os.BinderProxy@6f17f51 startId=41 args=Intent { cmp=com.android.bluetooth/.opp.BluetoothOppService }}
10-25 12:51:52.489 861-1561/? V/ActivityManager: Broadcast: Intent { act=android.btopp.intent.action.INCOMING_FILE_NOTIFICATION flg=0x10 cmp=com.android.bluetooth/.opp.BluetoothOppReceiver } ordered=false userid=0 callerApp=ProcessRecord{b1c8b46 26423:com.android.bluetooth/1002}
10-25 12:51:52.492 26423-26423/? D/ActivityThread: BDC-Calling onReceive: intent=Intent { act=android.btopp.intent.action.INCOMING_FILE_NOTIFICATION flg=0x10 cmp=com.android.bluetooth/.opp.BluetoothOppReceiver }, receiver=com.android.bluetooth.opp.BluetoothOppReceiver@61a38ae
10-25 12:51:52.492 26423-26423/? I/[Bluetooth.OPP]BluetoothOppReceiver: onReceive::action = android.btopp.intent.action.INCOMING_FILE_NOTIFICATION
10-25 12:51:52.492 26423-26423/? V/[Bluetooth.OPP]BluetoothOppReceiver: Receiver INCOMING_FILE_NOTIFICATION
10-25 12:51:52.496 26423-26423/? D/ActivityThread: BDC-RECEIVER handled : 0 / ReceiverData{intent=Intent { act=android.btopp.intent.action.INCOMING_FILE_NOTIFICATION flg=0x10 cmp=com.android.bluetooth/.opp.BluetoothOppReceiver } packageName=com.android.bluetooth resultCode=-1 resultData=null resultExtras=null}
10-25 12:51:52.497 26423-3411/? V/[Bluetooth.OPP]BtOppObexServer: insert contentUri: content://com.android.bluetooth.opp/btopp/24
10-25 12:51:52.497 26423-3411/? V/[Bluetooth.OPP]BtOppObexServer: mLocalShareInfoId = 24
10-25 12:51:52.497 26423-3411/? V/[Bluetooth.OPP]BtOppObexServer: acquire partial WakeLock
10-25 12:51:52.500 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 5 with null URI
10-25 12:51:52.500 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 6 with null URI
10-25 12:51:52.500 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 7 with null URI
10-25 12:51:52.500 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 8 with null URI
10-25 12:51:52.501 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 10 with null URI
10-25 12:51:52.501 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 13 with null URI
10-25 12:51:52.501 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 14 with null URI
10-25 12:51:52.501 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 15 with null URI
10-25 12:51:52.501 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 16 with null URI
10-25 12:51:52.501 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 17 with null URI
10-25 12:51:52.501 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 18 with null URI
10-25 12:51:52.501 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 19 with null URI
10-25 12:51:52.501 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 20 with null URI
10-25 12:51:52.501 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 21 with null URI
10-25 12:51:52.501 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 22 with null URI
10-25 12:51:52.501 26423-3412/? W/[Bluetooth.OPP]BtOppService: updateShare() called for ID 23 with null URI
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: insertShare ++
10-25 12:51:52.502 26423-3412/? E/[Bluetooth.OPP]BtOppService: insertShare found null URI at cursor!
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: Service adding new entry
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: ID      : 24
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: URI     : null
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: HINT    : UpdateMandoCar.zip
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: FILENAME: null
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: MIMETYPE: application/zip
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: DIRECTION: 1
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: DESTINAT: 40:9F:38:9C:8A:10
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: VISIBILI: 0
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: CONFIRM : 0
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: STATUS  : 190
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: TOTAL   : 2801484
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: CURRENT : 0
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: TIMESTAMP : 1540464712123
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: SCANNED : false
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: CARRIER : null
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppBatch: New Batch created for info 24
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: Service create new Batch 20 for INBOUND info 24
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppService: Service start server transfer new Batch 20 for info 24
10-25 12:51:52.502 26423-3412/? V/[Bluetooth.OPP]BtOppTransfer: start ++
10-25 12:51:52.502 26423-3412/? D/BluetoothAdapter: isEnabled
10-25 12:51:52.505 26423-3412/? V/[Bluetooth.OPP]BtOppTransfer: Create handler thread for batch 20
10-25 12:51:52.507 26423-3412/? V/[Bluetooth.OPP]BtOppTransfer: Start session for info 24 for batch 20

0 个答案:

没有答案