我写了我的第一个Android应用程序,一切都运行得很好,除了...在例程中,下面,ACTION_DISCOVERY_FINISHED似乎永远不会被调用(或广播或接收或其他).无论" else if "中的代码块是什么都不起作用.
我只在我的摩托罗拉Atrix上测试过,所以我想知道这是不是问题.由于我正在测试蓝牙功能,我认为我不能使用Android模拟器进行有效测试.
思考?
private BluetoothAdapter mBtAdapter;
mBtAdapter.startDiscovery();
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
//do something
}
else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
//do something else
}
}
}
Run Code Online (Sandbox Code Playgroud)