小编aak*_*024的帖子

我的Android应用多次检测到同一蓝牙设备

我正在使用Android开发人员网站上的代码来检测范围内的蓝牙设备,并将它们添加到ArrayAdapter中。问题是,每个设备被添加到ArrayAdapter的次数为5-6次。现在,我只是使用此处的代码:http : //developer.android.com/guide/topics/connectivity/bluetooth.html#DiscoveringDevices

这是我所拥有的:

mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();      
mBluetoothAdapter.startDiscovery();

final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        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
            mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

知道是什么原因造成的吗?我该怎么做才能将设备仅添加到ArrayAdapter一次,而不是5次?

java android bluetooth broadcastreceiver

2
推荐指数
1
解决办法
2235
查看次数

我在C中遇到了"冲突类型"错误

我正在研究一个C课程的程序,我必须输出一个形状的区域.

这是我在程序中的矩形区域的函数:

double rectangle() // calculate area of rectangle
{
    double length, width;

    printf("\nEnter length and width of rectangle: ");
    scanf("%g %g\n", &length, &width);

    return (length*width);
}
Run Code Online (Sandbox Code Playgroud)

这是我调用函数的地方 rectangle()

if(strncmp(shape, "rectangle", 15) == 0)
    area = rectangle();
Run Code Online (Sandbox Code Playgroud)

我在Linux Mint中使用Geany和GCC编译器.

我收到的错误是

"geometryv2.c:78:错误:'矩形'的冲突类型"

我不知道这里有什么冲突.带有return-type double的函数返回一个double.这里的任何帮助将不胜感激.我仍然是C的新手,这实际上是我的第一个C程序.

谢谢!

c user-defined-functions

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