BroadcastReceiver onReceive()从未调用

时间:2019-04-14 12:44:55

标签: java android broadcastreceiver

我正在尝试发现附近的蓝牙设备。我遵循了教程,但是我无法弄清楚为什么从未调用{ favorites: [], _id: 5cb32867d2dfea0cadd79ecb, name: 'Anna', userId: 'AF322', __v: 0 } 方法。即使onReceive()成功,也不会调用方法startDiscovery()。我已经为清单添加了适当的权限

onReceive()
if(adapter.isDiscovering()) {
                adapter.cancelDiscovery();

                if (adapter.startDiscovery())
                    test.setText("Searching >>>");

                IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
                Receiver receiver = new Receiver();
                registerReceiver(receiver, filter);
            }
}
if(!adapter.isDiscovering()) {

                if (adapter.startDiscovery())
                    test.setText("Searching >>>");


                IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
                Receiver receiver = new Receiver();
                registerReceiver(receiver, filter);
            }

0 个答案:

没有答案