android - 如何解决 Android 中的此 Windows 管理器错误?

标签 android bluetooth

我无法理解代码到底发生了什么。 我的代码有时运行良好,有时运行不正常。

我正在创建蓝牙连接。单击搜索按钮时我正在搜索设备。它为我提供了设备列表,我将其显示在 ListView 中。这一切都很好。

现在单击 listItem,我想将我的设备与从列表中选择的设备配对。 我已经使用此代码来执行此操作。

   listViewDetected.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,int position, long id) 
            {
                Log.i("Log", "ListItem is clicked at :"+position);
                posn = position;
                String str = (String) listViewDetected.getItemAtPosition(position);
                Log.i("Log", "ListItem is :"+str);
                bluetoothDevice=arrayListBluetoothDevices.get(position);
                final BluetoothDevice device = arrayListBluetoothDevices.get(position);
                Log.i("Log", "UUID string is :"+uid);
                new Thread() {
                    public void run() {
                        connect(device);
                    };
                }.start();
            }

            private void connect(BluetoothDevice bluetoothDevicess) {
                // TODO Auto-generated method stub
                Log.i("Log", "connect method after click: ");
                ParcelUuid[] uuids = servicesFromDevice(bluetoothDevicess);
                adapterPaired.notifyDataSetChanged();
                Log.i("Log", "service method executed");
            }
        });


public ParcelUuid[] servicesFromDevice(BluetoothDevice device) {
    try {
        Log.i("Log", "service method is called ");
        Class cl = Class.forName("android.bluetooth.BluetoothDevice");
        Class[] par = {};
        Method method = cl.getMethod("createBond", par);
        Object[] args = {};
        ParcelUuid[] retval = (ParcelUuid[]) method.invoke(device, args);
        if(retval==null)
        {
            Log.i("Log", "GOT the Array as null:");
        }
        else
        {
            Log.i("Log", "GOT the Array:"+retval.length);
        }
        /* for(int i = 0;i<retval.length;i++)
        {               Log.i("Log", "GOT  :  "+retval[i]);
        }*/
        return retval;
    } catch (Exception e) {
        Log.i("Log", "Inside catch of serviceFromDevice Method");
        e.printStackTrace();
        return null;
    }
}

有时它工作得很好。但有时它不起作用。

我再说一遍

有时它工作得很好。但有时它不起作用。甚至没有一行在执行 listItem clicked() 方法。

当它不工作时,我在 logcat 上得到它:

09-01 16:17:26.405: I/KeyInputQueue(171): Enqueueing touch event0
09-01 16:17:26.405: I/WindowManager(171): Read next event 0
09-01 16:17:26.405: I/WindowManager(171): Delivering pointer 0 > Window{4a6ea918 com.bdm/com.bdm.BluetoothDemo paused=false}
09-01 16:17:26.515: I/KeyInputQueue(171): Enqueueing touch event1
09-01 16:17:26.515: I/WindowManager(171): Read next event 1
09-01 16:17:26.515: I/WindowManager(171): Delivering pointer 1 > Window{4a6ea918 com.bdm/com.bdm.BluetoothDemo paused=false}

最佳答案

我得到了这个问题的解决方案。它的发生仅仅是因为 Brodcast Receiver。我当时正在点击 listItem,同时我的接收器被触发。在那里我调用了线程对象。所以有时,如果我的线程没有被调用,那么 listitem click 工作正常。感谢您的兴趣 friend 。谢谢。

关于android - 如何解决 Android 中的此 Windows 管理器错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12227165/

相关文章:

ios - GCDAsyncSocket 客户端/服务器无法通过 iOS 访问点工作

bluetooth - 使用 rfcomm 检查连接是否成功

Android Studio 无法识别 wav 文件

android - 无法加载资源:net::ERR_FILE_NOT_FOUND ionic 错误

javascript - Mapbox NavigationViewOptions 和 NavigationLauncherOptions

不再有广告的 Android Ble clear 设备

ios - 无法通过蓝牙共享 URL(UIActivityViewController)

bluetooth - FlutterBlue 特性

android - 使用 apache buildr 构建 android apk

java - Firebase 数据库规则 parent 跟踪 child