蓝牙低功耗APP适用于Nexus,但不适用于其他产品

时间:2014-12-09 19:18:13

标签: bluetooth bluetooth-lowenergy

我正在为连接设备(Nordic BLE)编写应用程序。

我使用了加速器蓝牙样本(蓝牙SIG)。

该应用程序在LG NEXUS 5上检测到我的物体,但在我的其他Acer Liquid Z200和我的Wiko GOA上没有检测到。

这些手机通常支持BLE。

提前感谢您的帮助。

尼古拉斯

这里是代码的粘贴:

public class MainActivity extends Activity {

    private BluetoothAdapter mBluetoothAdapter = null;
    private boolean mScanning = false;
    private Handler mHandler = new Handler();
    private ListAdapter mLeDeviceListAdapter;

    private static final long SCAN_TIMEOUT = 5000;

    static class ViewHolder {
        public TextView text;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("debug", ".");
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.activity_main);

        // Initializes Bluetooth adapter.
        final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
        mBluetoothAdapter = bluetoothManager.getAdapter();

        mLeDeviceListAdapter = new ListAdapter();

        ((ListView) this.findViewById(R.id.deviceList))
                .setAdapter(mLeDeviceListAdapter);
    }

    public void onScan(View view) {
        // check bluetooth is available on on
        if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
            Intent enableBtIntent = new Intent(
                    BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivity(enableBtIntent);
            return;
        }

        scanLeDevice(!mScanning);
    }

    private void setScanState(boolean value) {
        mScanning = value;
        setProgressBarIndeterminateVisibility(value);
        ((Button) this.findViewById(R.id.scanButton)).setText(value ? "Stop"
                : "Scan");
    }

    private void scanLeDevice(final boolean enable) {
        if (enable) {
            // scan for SCAN_TIMEOUT
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    setScanState(false);
                    mBluetoothAdapter.stopLeScan(mLeScanCallback);
                }
            }, SCAN_TIMEOUT);

            setScanState(true);
            mLeDeviceListAdapter.clear();
            mLeDeviceListAdapter.notifyDataSetChanged();

            UUID[] uuids = new UUID[1];
            uuids[0] = UUID.fromString("6E400001-B5A3-F393-E0A9-E50E24DCCA9K");
            mBluetoothAdapter.startLeScan( uuids, mLeScanCallback);
        } else {
            setScanState(false);
            mBluetoothAdapter.stopLeScan(mLeScanCallback);
        }
    }

    // Device scan callback.
    private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {

        @Override
        public void onLeScan(final BluetoothDevice device, int rssi,
                byte[] scanRecord) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                Log.d("debug", "device found");//DOES NOT APPEND ON ACER AND WIKO   
                }
            });
        }
    };

0 个答案:

没有答案