用Logclass跟踪运行时显示onReceive()方法没有调用,为什么?
动态注册广播接收器
private void discoverDevices () {
Log.e("MOHAB","BEFORE ON RECEIVE");
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Log.e("MOHAB","ON RECEIVE");
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Add the name and address to an array adapter to show in a ListView
Bluetooth b = new Bluetooth(device.getName(),device.getAddress());
list.add(b);
}
}
};
Log.e("MOHAB","create intentFilter");
// …Run Code Online (Sandbox Code Playgroud) 我有一个使用蓝牙和连接设备的应用程序,无法使用BluetoothAdapter.getDefaultAdapter()找到任何设备.startDiscovery(); 它在发现之前工作得很好.尝试过其他应用程序,它也不适用于其他应用程序.但我尝试配对的设备(Arduino bt-module)可以在Android设置中找到.知道我能尝试什么吗?我实现了http://developer.android.com/guide/topics/connectivity/bluetooth.html上描述的所有内容,它在更新之前有效.