2

i want to control my phone using an external bluetooth-device with SPP (RFCOMM). so i took the BluetoothChat-Example and adopted the read-part to handle my commands sent by the external device. when i use the external device, it powers up, establishes a connection, sends the command and turns off again. the app is also working when running in the background. so everything works fine so far ..

the two problem i still have are:

a) if i switch-off and on bluetooth on the phone, it will no longer listen to incoming connections from the external device. i have to start the app again to make it work.

b) closing the app is also ok, the thing still works. but when i kill all processes, the app is also closed and will not work longer. is there a possibility, to relaunch the app automatically?

thanks!

PS: i am an android beginner.

4

2 回答 2

0

我设法运行该服务,它工作正常!我还为 boot_complete-event 添加了一个广播接收器 - 也可以。

直到现在唯一没有解决的问题是,当我杀死所有进程时,我的服务和接收器停止工作!有没有办法让它们保持活力或自动重新启动它们?谢谢!

于 2012-11-05T15:14:23.477 回答
0

还没有使用过蓝牙,但我想我可以根据我在 Android 方面的经验给你一些指导

a)我假设您已经为蓝牙连接实现了服务,对吗?如果是这样,您可以为 ACTION_CONNECTION_STATE_CHANGED 事件实现广播接收器。当接收到这个广播时,您可以处理蓝牙设备的连接和断开。

http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#ACTION_CONNECTION_STATE_CHANGED

b)我不确定你是否能做到这一点。如果您使用系统 AlarmManager 编写警报以重新打开您的应用程序并且操作系统终止您的进程,则警报也会被终止。

希望能帮助到你。

于 2012-10-22T18:34:55.450 回答