小编Fra*_*zzi的帖子

Android 6.0 - 蓝牙 - Action_Found广播意图不存在代码

UPDATE

我尝试了许多代码,也是从互联网上显示的例子.他们每个都遵循我的方法.经过几个小时的测试,我得出结论,在Android 6.0上没有机会实现未知设备的蓝牙发现,我们只能检索绑定的设备.我很确定这个Android版本有什么东西.

如果有人知道如何解决这个问题,我真的很感激任何帮助.


原帖

我的代码工作正常,但没有找到设备.我只收到DISCOVERY_STARTED和DISCOVERY_FINISHED,因此找不到任何设备,但使用系统应用程序可以找到这些设备.

这是我的应用程序的代码,希望它可以提供帮助.

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 
    bluetoothAdapter= BluetoothAdapter.getDefaultAdapter();

//other stuff...

    IntentFilter filter=new IntentFilter();
    filter.addAction(BluetoothDevice.ACTION_FOUND);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);

    registerReceiver(myreceiver,filter);
}

final BroadcastReceiver myreceiver = new BroadcastReceiver(){

    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();

        Log.i("test","RECEIVED: "+ action);
        if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
        }
        else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
        }

        if(BluetoothDevice.ACTION_FOUND.equals(action))
        {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            Log.i("test", device.getName() + "\n" + device.getAddress());
        }
    }};

public void scanDevices(View v){

        if (bluetoothAdapter.isEnabled()){

            bluetoothAdapter.startDiscovery();
        }
}
Run Code Online (Sandbox Code Playgroud)

我已经设置了权限: …

android bluetooth discovery

6
推荐指数
1
解决办法
1920
查看次数

C++ - 在单独的文件中实现内部模板类的模板方法

我正在实现这个类:

#ifndef LIST_H
#define LIST_H

template <typename ListType> class List{
public:

    enum ListPosition{LIST_START=-2,LIST_END=-1};
    enum Order{ASCENDANT,DESCENDANT};

    template  <typename NodeType> class ListNode{

        public:

            ListNode(const NodeType &value,const ListNode<NodeType>*const pElement, const ListNode<NodeType>*const nElement);
            ~ListNode();

            ListNode<NodeType> *const previous() const;
            ListNode<NodeType> *const next() const;

            void setPrevious(const ListNode<NodeType> *const pElement);
            void setNext(const ListNode<NodeType> *const nElement);
            void setValue(const NodeType& value);

        private:

            ListNode<NodeType> *pElement;
            ListNode<NodeType> *nElement;
            NodeType *value;
    };

    List();
    List(const List<ListType> &list);
    ~List();

    bool contains(const ListType& value) const;

    ListType& get(const int pos) const;
    ListNode<ListType>& getNode(const int pos) const; …
Run Code Online (Sandbox Code Playgroud)

c++ templates class definition

3
推荐指数
1
解决办法
1173
查看次数

标签 统计

android ×1

bluetooth ×1

c++ ×1

class ×1

definition ×1

discovery ×1

templates ×1