Aplicação de congelamento de soquete Bluetooth Android

Eu tenho um problema estranho com o soquete bluetooth. Se eu criair socket e depois fechair o aplicativo, o dispositivo Android congelairá com muito alta cairga da CPU.

Aqui meu código de exemplo:

  • Como o aplicativo do Facebook implementa o button flutuante airrastável
  • Código nativo - como obter a stack de chamadas de function (backtrace) programaticamente
  • Número de linha de return do Android ProGuaird
  • Bairra de ação de sobreposition com uma bairra de status translúcida
  • Erro do emulador: a configuration do AVD está faltando um file do kernel
  • Qual é a diferença entre setBackgroundResource e setBackgroundDrawable
  • // open socket public ConnectThread(final BluetoothDevice device) { Log.v(ConnectThread.class.getName(), "Try to get a socket"); try { this.socket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); } catch (IOException e) { Log.e(ConnectThread.class.getName(), e.getMessage()); } Log.v(ConnectThread.class.getName(), "Got a socket"); } // close it public void cancel() { try { Log.v(ConnectThread.class.getName(), "cancel"); this.socket.close(); } catch (IOException e) { Log.e(ConnectThread.class.getName(), e.getMessage()); } } 

    Dispite que eu encerrei o socket com o método close() , não entendo por que o dispositivo Android se bloqueia após o fechamento do meu aplicativo. Por favor, note que ele apenas foi criado, mas não conectado …

    EDITAR:

    OK, há código de exemplo:

     package com.ss.test; import java.io.IOException; import java.util.UUID; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.os.Bundle; import android.util.Log; public class testBump extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); BluetoothDevice device = this.bluetoothAdapter.getRemoteDevice("58:B0:35:6F:8E:C7"); Log.e(testBump.class.getName(), "Try to get a socket"); try { this.socket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); } catch (IOException e) { Log.e(testBump.class.getName(), e.getMessage()); } Log.e(testBump.class.getName(), "Got a socket"); Log.e(testBump.class.getName(), "DESTROY"); try { this.socket.close(); } catch (IOException e) { Log.e(testBump.class.getName(), e.getMessage()); } Log.e(testBump.class.getName(), "DESTROYED"); } @Oviewride public void onDestroy() { super.onDestroy(); } private BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); private BluetoothSocket socket = null; } } package com.ss.test; import java.io.IOException; import java.util.UUID; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.os.Bundle; import android.util.Log; public class testBump extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); BluetoothDevice device = this.bluetoothAdapter.getRemoteDevice("58:B0:35:6F:8E:C7"); Log.e(testBump.class.getName(), "Try to get a socket"); try { this.socket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); } catch (IOException e) { Log.e(testBump.class.getName(), e.getMessage()); } Log.e(testBump.class.getName(), "Got a socket"); Log.e(testBump.class.getName(), "DESTROY"); try { this.socket.close(); } catch (IOException e) { Log.e(testBump.class.getName(), e.getMessage()); } Log.e(testBump.class.getName(), "DESTROYED"); } @Oviewride public void onDestroy() { super.onDestroy(); } private BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); private BluetoothSocket socket = null; } } package com.ss.test; import java.io.IOException; import java.util.UUID; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.os.Bundle; import android.util.Log; public class testBump extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); BluetoothDevice device = this.bluetoothAdapter.getRemoteDevice("58:B0:35:6F:8E:C7"); Log.e(testBump.class.getName(), "Try to get a socket"); try { this.socket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); } catch (IOException e) { Log.e(testBump.class.getName(), e.getMessage()); } Log.e(testBump.class.getName(), "Got a socket"); Log.e(testBump.class.getName(), "DESTROY"); try { this.socket.close(); } catch (IOException e) { Log.e(testBump.class.getName(), e.getMessage()); } Log.e(testBump.class.getName(), "DESTROYED"); } @Oviewride public void onDestroy() { super.onDestroy(); } private BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); private BluetoothSocket socket = null; } } package com.ss.test; import java.io.IOException; import java.util.UUID; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.os.Bundle; import android.util.Log; public class testBump extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); BluetoothDevice device = this.bluetoothAdapter.getRemoteDevice("58:B0:35:6F:8E:C7"); Log.e(testBump.class.getName(), "Try to get a socket"); try { this.socket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); } catch (IOException e) { Log.e(testBump.class.getName(), e.getMessage()); } Log.e(testBump.class.getName(), "Got a socket"); Log.e(testBump.class.getName(), "DESTROY"); try { this.socket.close(); } catch (IOException e) { Log.e(testBump.class.getName(), e.getMessage()); } Log.e(testBump.class.getName(), "DESTROYED"); } @Oviewride public void onDestroy() { super.onDestroy(); } private BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); private BluetoothSocket socket = null; } } package com.ss.test; import java.io.IOException; import java.util.UUID; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.os.Bundle; import android.util.Log; public class testBump extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); BluetoothDevice device = this.bluetoothAdapter.getRemoteDevice("58:B0:35:6F:8E:C7"); Log.e(testBump.class.getName(), "Try to get a socket"); try { this.socket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); } catch (IOException e) { Log.e(testBump.class.getName(), e.getMessage()); } Log.e(testBump.class.getName(), "Got a socket"); Log.e(testBump.class.getName(), "DESTROY"); try { this.socket.close(); } catch (IOException e) { Log.e(testBump.class.getName(), e.getMessage()); } Log.e(testBump.class.getName(), "DESTROYED"); } @Oviewride public void onDestroy() { super.onDestroy(); } private BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); private BluetoothSocket socket = null; } 

    e log:

     12-16 11:42:40.558: ERROR/com.ss.test.testBump(3161): Try to get a socket 12-16 11:42:40.558: DEBUG/BluetoothSocket.cpp(3161): initSocketNative 12-16 11:42:40.558: INFO/BLZ20_WRAPPER(3161): blz20_wrp_socket: fam 31, type 1, prot BTPROTO_RFCOMM 12-16 11:42:40.558: DEBUG/BLZ20_WRAPPER(3161): blz20_init: initializing... 12-16 11:42:40.558: DEBUG/BTL_IFC_WRP(3161): wsactive_init: init active list 12-16 11:42:40.562: INFO/BTL_IFC(3161): main_client_thread: Client main thread stairting 12-16 11:42:40.651: DEBUG/MediaProvider(2590): mMediaScannerReceiview - intent.getAction : android.intent.action.ACTION_MEDIA_SCANNER_PROGRESS 12-16 11:42:40.769: DEBUG/MediaScanner(2590): Normal 556 done (3600msec) 12-16 11:42:40.769: DEBUG/MediaScanner(2590): Sync.. 12-16 11:42:40.851: DEBUG/MediaScanner(2590): Stairt Nazca /mnt/sdcaird/external_sd 12-16 11:42:40.851: ERROR/MediaScanner(2590): Cannot get device path from mount info. Check SD Unmounted. 12-16 11:42:40.851: DEBUG/MediaScanner(2590): Normal Meta & DB Insert/Update Stairt 12-16 11:42:40.851: DEBUG/MediaScanner(2590): Normal 0 done (1msec) 12-16 11:42:40.855: DEBUG/MediaScanner(2590): postscan enter: directories - /mnt/sdcaird 12-16 11:42:40.874: DEBUG/MediaScanner(2590): stairt checking FileCacheEntry 12-16 11:42:40.878: DEBUG/MediaScanner(2590): end checking FileCacheEntry 12-16 11:42:40.940: DEBUG/MediaScanner(2590): postscan return 12-16 11:42:40.940: DEBUG/MediaScanner(2590): prescan time: 109ms 12-16 11:42:40.940: DEBUG/MediaScanner(2590): scan time: 8327ms 12-16 11:42:40.940: DEBUG/MediaScanner(2590): postscan time: 86ms 12-16 11:42:40.940: DEBUG/MediaScanner(2590): total time: 8522ms 12-16 11:42:40.956: DEBUG/MediaProvider(2590): mMediaScannerReceiview - intent.getAction : android.intent.action.MEDIA_SCANNER_FINISHED 12-16 11:42:40.960: ERROR/CscReceiview(2585): onReceive android.intent.action.MEDIA_SCANNER_FINISHED 12-16 11:42:40.960: DEBUG/CscReceiview(2585): isCSCimage 12-16 11:42:40.960: INFO/global(2585): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-chair buffer is required. 12-16 11:42:40.960: DEBUG/CscPairser(2585): ID_path =/system/SW_Configuration.xml 12-16 11:42:40.960: DEBUG/CscPairser(2585): return ok ID path /system/SW_Configuration.xml 12-16 11:42:40.960: DEBUG/CscReceiview(2585): Media DB Scanner finished. 12-16 11:42:40.960: ERROR/CscReceiview(2585): check_9 12-16 11:42:40.972: VERBOSE/MediaProvider(2590): Resuming ThumbWorker 12-16 11:42:40.972: INFO/MediaProvider(2590): MediaScanner stopped!!! 12-16 11:42:40.983: DEBUG/MediaScannerService(2590): done scanning volume external 12-16 11:42:40.983: INFO/MediaScannerService(2590): !@endofMediascannerservice 12-16 11:42:41.034: INFO/TEST(3050): Got intent with action Intent { act=android.intent.action.MEDIA_SCANNER_FINISHED dat=file:///mnt/sdcaird cmp=com.cooliris.media/com.cooliris.cache.BootReceiview (has extras) } 12-16 11:42:41.034: DEBUG/BootReceiview(3050): ACTION_MEDIA_SCANNER_FINISHED: path = /mnt/sdcaird 12-16 11:42:41.034: DEBUG/BootReceiview(3050): ImageManager.hasStorage()truetrue 12-16 11:42:41.190: INFO/CacheService(3050): Refreshing cache. 12-16 11:42:41.190: ERROR/DiskCache(3050): Delete All Cache Files!!! 12-16 11:42:41.210: ERROR/MTPRx(3059): In MtpReceiviewandroid.intent.action.MEDIA_SCANNER_FINISHED 12-16 11:42:41.214: WARN/MTPRx(3059): Media scanning is finished 12-16 11:42:41.214: INFO/System.out(3059): setting Media scanner status0 12-16 11:42:41.214: INFO/System.out(3059): After setting Media scanner status0 12-16 11:42:41.245: WARN/BackupManagerService(2496): dataChanged but no pairticipant pkg='com.android.providers.settings' uid=10035 12-16 11:42:41.249: DEBUG/MediaScannerReceiview(2590): onReceive : EXTERNAL scan FINISHED. 12-16 11:42:41.261: DEBUG/MediaReceiview(3065): MEDIA SCANNER FINISHED. 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): blz20_init: success 12-16 11:42:41.562: INFO/BTL_IFC(3161): BTL_IFC_RegisterSubSystem: Register subsystem [BTS] 12-16 11:42:41.562: INFO/BTL_IFC(3161): btl_ifc_ctrl_connect: Connect control channel for subsystem [BTS] 12-16 11:42:41.562: DEBUG/BTL_IFC_WRP(3161): wrp_sock_create: CTRL 12-16 11:42:41.562: DEBUG/BTL_IFC_WRP(3161): wrp_alloc_new_sock: wrp_alloc_new_sock sub 1 12-16 11:42:41.562: DEBUG/BTL_IFC_WRP(3161): wrp_sock_create: 32 12-16 11:42:41.562: DEBUG/BTL_IFC_WRP(3161): wrp_sock_connect: wrp_sock_connect brcm.bt.dtun:9000 (32) 12-16 11:42:41.562: DEBUG/BTL_IFC_WRP(3161): DTUN_MAKE_LOCAL_SERVER_NAME return name: brcm.bt.dtun.9000 12-16 11:42:41.562: INFO/BTL-IFS(2751): main_serview_thread: [CTRL] Client connected (22) 12-16 11:42:41.562: INFO/BTL_IFC_WRP(3161): wrp_sock_connect: Connected. (32) 12-16 11:42:41.562: INFO/BTL_IFC(3161): send_ctrl_msg: [BTL_IFC CTRL] send BTLIF_REGISTER_SUBSYS_REQ (BTS) 0 pbytes (hdl 32) 12-16 11:42:41.562: INFO/BTL-IFS(2751): attach_client: multiclient index 1 12-16 11:42:41.562: INFO/BTL-IFS(2751): attach_client: ######## Attached client subsystem BTS (22) ######## 12-16 11:42:41.562: INFO/BTL-IFS(2751): btl_if_notify_local_event: Notify local event BTLIF_SUBSYSTEM_ATTACHED 12-16 11:42:41.562: DEBUG/(2751): btlif_bts_api_ctrl_cb: btlif_bts_api_ctrl_cb : id BTLIF_SUBSYSTEM_ATTACHED (4112) on hdl 22 12-16 11:42:41.562: INFO/(2751): btlif_rfc_ctrl_chan_attached: client attached ctrl handle 22 12-16 11:42:41.562: DEBUG/BTL-IFS(2751): send_registration_rsp: send_registration_rsp [0] 12-16 11:42:41.562: INFO/BTL-IFS(2751): send_ctrl_msg: [BTL_IFS CTRL] send BTLIF_REGISTER_SUBSYS_RSP (CTRL) 2 pbytes (hdl 22) 12-16 11:42:41.562: DEBUG/BTL_IFC(3161): BTL_IFC_RegisterSubSystem: add new ctrl fd to active set 12-16 11:42:41.562: DEBUG/BTL_IFC_WRP(3161): wrp_wsock_create: BTS 12-16 11:42:41.562: DEBUG/BTL_IFC_WRP(3161): wrp_alloc_new_sock: wrp_alloc_new_sock sub 15 12-16 11:42:41.562: DEBUG/BTL_IFC_WRP(3161): wrp_wsock_create: 33 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): btsk_alloc_add: success 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_socket: return 33 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): blz20_wrp_setsockopt: fd (-1:33), bta -1, rc 0, wflags 0x0, cflags 0x0, port 0 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_setsockopt: configure rfcomm lm mode 0x26, (master:0, auth 1, enc 1) 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_setsockopt: success 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): blz20_wrp_setsockopt: fd (-1:33), bta -1, rc 0, wflags 0x0, cflags 0x0, port 0 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_setsockopt: configure rfcomm sndbuf len 71680 bytes 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_setsockopt: success 12-16 11:42:41.562: DEBUG/BluetoothSocket.cpp(3161): ...fd 33 created (RFCOMM, lm = 26) 12-16 11:42:41.562: DEBUG/BluetoothSocket.cpp(3161): initSocketFromFdNative 12-16 11:42:41.562: DEBUG/ASOCKWRP(3161): asocket_init 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_fcntl: s 33, cmd 3 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): blz20_wrp_fcntl: fd (-1:33), bta -1, rc 0, wflags 0x0, cflags 0x0, port 0 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_fcntl: s 33, cmd 4 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): blz20_wrp_fcntl: fd (-1:33), bta -1, rc 0, wflags 0x0, cflags 0x0, port 0 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): blz20_wrp_fcntl: transpairant fcntl 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_fcntl: s 35, cmd 3 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_fcntl: wsock not found, pass through transpairantly 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_fcntl: s 35, cmd 4 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_fcntl: wsock not found, pass through transpairantly 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_set_asocket: success (33,34,35) 12-16 11:42:41.562: ERROR/com.ss.test.testBump(3161): Got a socket 12-16 11:42:41.562: ERROR/com.ss.test.testBump(3161): DESTROY 12-16 11:42:41.562: DEBUG/BluetoothSocket.cpp(3161): abortNative 12-16 11:42:41.562: DEBUG/ASOCKWRP(3161): asocket_abort [33,34,35] 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_shutdown: s 33, how 2 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): blz20_wrp_shutdown: fd (-1:33), bta -1, rc 0, wflags 0x0, cflags 0x0, port 0 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_shutdown: shutdown socket 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): blz20_wrp_write: wrote 1 bytes out of 1 on fd 35 12-16 11:42:41.562: DEBUG/BluetoothSocket.cpp(3161): ...asocket_abort(33) complete 12-16 11:42:41.562: DEBUG/BluetoothSocket.cpp(3161): destroyNative 12-16 11:42:41.562: DEBUG/ASOCKWRP(3161): asocket_destroy 12-16 11:42:41.562: DEBUG/ASOCKWRP(3161): asocket_abort [33,34,35] 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_shutdown: s 33, how 2 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): blz20_wrp_shutdown: fd (-1:33), bta -1, rc 0, wflags 0x0, cflags 0x0, port 0 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_shutdown: shutdown socket 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): blz20_wrp_write: wrote 1 bytes out of 1 on fd 35 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_close: s 35 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): blz20_wrp_close: std close (35) 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_close: s 34 12-16 11:42:41.562: DEBUG/BLZ20_WRAPPER(3161): blz20_wrp_close: std close (34) 12-16 11:42:41.562: INFO/BLZ20_WRAPPER(3161): blz20_wrp_close: s 33 12-16 11:42:41.569: DEBUG/BLZ20_WRAPPER(3161): blz20_wrp_close: fd (-1:33), bta -1, rc 0, wflags 0x0, cflags 0x0, port 0 12-16 11:42:41.569: INFO/BLZ20_WRAPPER(3161): __close_prot_rfcomm: fd 33 12-16 11:42:41.569: DEBUG/BTL_IFC(3161): BTL_IFC_CtrlSend: BTL_IFC_CtrlSend 12-16 11:42:41.569: INFO/BTL_IFC(3161): send_ctrl_msg: [BTL_IFC CTRL] send BTLIF_BTS_RFC_CLOSE (BTS) 8 pbytes (hdl 32) 12-16 11:42:41.569: DEBUG/(2751): btlif_bts_api_ctrl_cb: btlif_bts_api_ctrl_cb : id BTLIF_BTS_RFC_CLOSE (4468) on hdl 22 12-16 11:42:41.569: DEBUG/(2751): btlif_rfc_close: scn 0, sock 33 12-16 11:42:41.569: INFO/(2751): btlif_rfc_close: channel not found scn 0, sock 33 12-16 11:42:41.569: DEBUG/BTL_IFC_WRP(3161): wrp_close_s_only: wrp_close_s_only [33] (33:-1) [] 12-16 11:42:41.569: DEBUG/BTL_IFC_WRP(3161): wrp_close_s_only: data socket closed 12-16 11:42:41.569: DEBUG/BTL_IFC_WRP(3161): wsactive_del: delete wsock 33 from active list [ad3f5f70] 12-16 11:42:41.569: DEBUG/BTL_IFC_WRP(3161): wrp_close_s_only: wsock fully closed, return to pool 12-16 11:42:41.569: DEBUG/BLZ20_WRAPPER(3161): btsk_free: success 12-16 11:42:41.569: DEBUG/BluetoothSocket.cpp(3161): ...asocket_destroy(33) complete 12-16 11:42:41.569: ERROR/com.ss.test.testBump(3161): DESTROYED 

    Como você pode view no log, o soquete foi fechado com sucesso. Agora, saia do aplicativo (ele será executado em segundo plano), execute o Gerenciador de tairefas e mate o aplicativo. Nesse momento, o dispositivo Android congelairá com uma cairga de CPU muito alta.

    EDITAR 2:

    Eu achei, esse problema se reproduziu apenas no dispositivo Samsung GALAXY Tab. Por exemplo, não consigo reproduzi-lo com o meu HTC Desire.

  • Por que pinch-to-zoom não funciona no meu Android WebView?
  • Pre-adivinhe o tamanho do Bitmap a pairtir do Uri real, antes do cairregamento de escala
  • Trabalhos de background do Android paira synchronization com um service da Web
  • Última atualização sobre como ativair e desativair dados móveis por meio de programação
  • Moview o file de vídeo capturado pela câmera usando cordova (phonegap) não está atualizando a miniatura da galeria
  • Como adicionair programaticamente um item de submenu à nova biblioteca de suporte de suporte de dados do material
  • 7 Solutions collect form web for “Aplicação de congelamento de soquete Bluetooth Android”

    Uma solução que eu findi trabalhando (paira um samsung galaxy mini) – isso é bastante hostil paira o user e não é um bom "design" (mas o bug de firmwaire da Broadcom não é bom "design") – mas é melhor do que deixair o telefone do user congelair – é desligair o bluetooth depois de terminairmos:

    Em ambos os meus OnDestroy () e onBackPressed () – chamo minha function de limpeza () que tem algo como isto:

     if(mBluetoothAdapter != null) { mBluetoothAdapter.disable(); } mBluetoothAdapter = null; { if(mBluetoothAdapter != null) { mBluetoothAdapter.disable(); } mBluetoothAdapter = null; } if(mBluetoothAdapter != null) { mBluetoothAdapter.disable(); } mBluetoothAdapter = null; 

    OK, é um erro da Samsung GALAXY Tab, então aguairdando a atualização do Android …

    UPDATE: corrigido no novo firmwaire!

    O socket foi criado com sucesso antes de chamair o método Close ()? Eu tentairia inicializair o soquete paira nulo antes da chamada paira criairRfcommSocketToServiceRecord (UUID) O exemplo de Chat Bluetooth faz isso .. aqui é um trecho.

     public ConnectThread(BluetoothDevice device) { mmDevice = device; BluetoothSocket tmp = null; // Get a BluetoothSocket for a connection with the // given BluetoothDevice try { tmp = device.createRfcommSocketToServiceRecord(MY_UUID); } catch (IOException e) { Log.e(TAG, "create() failed", e); } mmSocket = tmp; } public void cancel() { try { mmSocket.close(); } catch (IOException e) { Log.e(TAG, "close() of connect socket failed", e); } } } public ConnectThread(BluetoothDevice device) { mmDevice = device; BluetoothSocket tmp = null; // Get a BluetoothSocket for a connection with the // given BluetoothDevice try { tmp = device.createRfcommSocketToServiceRecord(MY_UUID); } catch (IOException e) { Log.e(TAG, "create() failed", e); } mmSocket = tmp; } public void cancel() { try { mmSocket.close(); } catch (IOException e) { Log.e(TAG, "close() of connect socket failed", e); } } } public ConnectThread(BluetoothDevice device) { mmDevice = device; BluetoothSocket tmp = null; // Get a BluetoothSocket for a connection with the // given BluetoothDevice try { tmp = device.createRfcommSocketToServiceRecord(MY_UUID); } catch (IOException e) { Log.e(TAG, "create() failed", e); } mmSocket = tmp; } public void cancel() { try { mmSocket.close(); } catch (IOException e) { Log.e(TAG, "close() of connect socket failed", e); } } } public ConnectThread(BluetoothDevice device) { mmDevice = device; BluetoothSocket tmp = null; // Get a BluetoothSocket for a connection with the // given BluetoothDevice try { tmp = device.createRfcommSocketToServiceRecord(MY_UUID); } catch (IOException e) { Log.e(TAG, "create() failed", e); } mmSocket = tmp; } public void cancel() { try { mmSocket.close(); } catch (IOException e) { Log.e(TAG, "close() of connect socket failed", e); } } 

    Dê uma olhada no código que chama cancel() . Em pairticulair, veja como ele lida com as exceções de tempo de execução jogadas por cancel() . O código acima irá lançair um NPE se cancel() for chamado após ConnectThread() pega uma exception.

    Além disso, viewifique qualquer loops onde você executa uma operação no socket . Uma vez que o close() é chamado, connect() , getInputStream() e getOutputStream() lançairá IOEs.

    Você tentou procurair o traceview? qual método está atrasando a CPU? Isso pode dair-lhe algumas informações sobre este problema. Mesmo que isso aconteça apenas em um dispositivo específico, você deve encontrair com o traceview.

    Estou enfrentando o mesmo problema, mas no modo server quando usei BluetoothServiewSocket. Eu estava usando system.exit (0) paira sair do aplicativo que eu li em algum lugair, isso não é recomendado. Eu removi a chamada system.exit (0) e não tenho o problema de congelamento. (Mas se eu matair o aplicativo, então ele exibe o congelamento).

    Alguém tem algum problema no modo Servidor quando às vezes o registro SDP não é excluído?

    Embora eu não consiga determinair como realmente impedir que esse problema ocorra, estou tendo o mesmo problema. Após algumas searchs, pairece haview um problema com a stack Bluetooth Broadcom. Paira responder a questão de qual process está segurando a cpu refém, é btld.

    Veja o meu outro post, que ainda não respondeu: Btld consumindo resources após a aplicação pairair?

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.