我正在为 SDK 10 (2.3.3) 编译:
android:minSdkVersion="10"
android:targetSdkVersion="16"
我正在两部索尼爱立信智能手机上进行测试。一个有Android 2.3.7,另一个有4.0.1。
我listenUsingInsecureRfcommWithServiceRecord
用来在蓝牙上打开一个新的服务器套接字并监听连接。
如果连接被成功接受,那么一切正常。我什至可以尝试取消服务器套接字,但这似乎不会影响刚刚创建的连接套接字。
但是,当我想在接受任何连接之前取消服务器套接字时,一旦bluetoothServerSocket.close();
执行该行,整个活动就会关闭并且进程终止。此外,这不是我可以处理的常规异常。
实际上甚至 logcat 本身也退出了!我必须再次快速执行它以获取您在下面看到的错误:
Zygote D Process 25471 terminated by signal (11)
295 InputDispatcher W channel '2c2e20a8 com.pligor.test/activities.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
295 InputDispatcher E channel '2c2e20a8 com.pligor.test/activities.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
295 dalvikvm D GC_FOR_ALLOC freed 1299K, 21% free 13252K/16583K, paused 93ms
295 InputDispatcher W Attempted to unregister already unregistered input channel '2c2e20a8 com.pligor.test/activities.MainActivity (server)'
295 BluetoothService D Tracked app 25471 diedType:10
295 BluetoothService D Removing service record 10009 for pid 25471
132 SurfaceFlinger D Release buffer at 0x61c08
295 WindowManager I WINDOW DIED Window{2c2e20a8 com.pligor.test/activities.MainActivity paused=false}
295 ActivityManager I Process com.pligor.test (pid 25471) has died.
295 ActivityManager W Force removing ActivityRecord{2c021800 com.pligor.test/activities.MainActivity}: app died, no saved state
295 WindowManager W Failed looking up window
295 WindowManager W java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@2bf3e798 does not exist
295 WindowManager W at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7165)
295 WindowManager W at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7156)
295 WindowManager W at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1545)
295 WindowManager W at android.os.BinderProxy.sendDeathNotice(Binder.java:417)
295 WindowManager W at dalvik.system.NativeStart.run(Native Method)
295 WindowManager I WIN DEATH: null
295 BluetoothEventLoop D Property Changed: UUIDs : 11
295 hAdapterStateMachine D BluetoothOn process message: 51
295 InputManagerService W Got RemoteException sending setActive(false) notification to pid 25471 uid 10040
注意:由信号 (11) 终止的进程意味着分段错误 ( http://en.wikipedia.org/wiki/SIGSEGV )。
编辑
我使用以下代码( )创建蓝牙Scala
服务器套接字:
private val bluetoothServerSocket: BluetoothServerSocket = try {
bluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord(MY_SERVICE_NAME_INSECURE, MY_UUID_INSECURE);
}
catch {
case e: IOException => throw new ServerSocketException;
}
我使用此代码关闭蓝牙套接字:
try {
isCancelled = true;
bluetoothServerSocket.close();
} catch {
case e: IOException => throw new NotClosedException;
}