У меня есть приложение для Android, которое управляет соединениями и передачей по Bluetooth на основе примера Google BluetoothChat .
. Имеет 3 потока:
- Oneиз них действует как «подключение к» (например, режим клиента).
- Второй действует как «прослушивание» (как сервер), и он ожидает / прослушивает подключение устройства к нему.
Третий - тот, кто управляет развитием.Он записывает и читает сообщения, отправленные через сокет, с помощью 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;
}
}
}
Он действительно очень хорошо работает для передачи текста и данных между устройствами.
Дело в том, что когда файл используется совместно, например, просто отправляя файл по соединению Bluetooth, например, изображение или zip-файл, эти данные не читаются InputStreamReader, который считывает все сообщения, которые яотправляю.
То, что я на самом деле видел (я мог видеть это в logcat), это то, что набор классов, связанных с OPP (Object Push Profile), управляет всеми соединениями и информацией оЭто.
Но я не могу найти в Документации для Android этот профиль среди доступных профилей Bluetooth для Android, и я также не могу прослушать намерение, которое вызывается при использовании этого типа передачи.
Мне нужноскажем, что устройство, отправляющее файл, - это ноутбук с Windows, и я не знаю, как они это делают.
Итак, как я могу прослушать это событие, потому что оно должно быть системной трансляцией или есть какие-то другие?способ получить уведомление, когда входящий файл отправляется мне?Например:
Журналы, в которых я нашел службы и прослушиватели 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