Как найти версию Android Bluetooth? - PullRequest
6 голосов
/ 03 февраля 2012

Мне нужно программно найти версию Android Bluetooth на телефоне. Может кто-нибудь мне подскажет, как это сделать?

Ответы [ 4 ]

1 голос
/ 24 апреля 2019

Насколько я знаю (и я провел много исследований) нет никакого способа узнать, какая аппаратная версия вашего устройства Android Bluetooth . (4.0, 4.2, 5.0, ...)

Некоторые люди утверждают, что у них есть приложение, которое может это сделать, но я никогда не видел работающего примера. Эти приложения показывают много номеров версий, но не аппаратную версию Bluetooth.

Некоторые люди придумывают трюк, который показывает номер версии программного обеспечения Bluetooth, но это не то, что мы хотим знать.

Есть некоторые хитрости, чтобы получить возможности устройства Bluetooth, но опять же, это не то, что мы хотим знать.

1 голос
/ 31 мая 2014

ИМХО, с андроидом можно различить только наличие Bluetooth или Bluetooth_LE.Но я сомневаюсь в поддержке Android при определении версий Bluetooth (например, BT2.0, BT2.1 + EDR, BT3.0 и т. Д.).Способ программной идентификации только присутствия BT или BLE может быть следующим:

PackageManager pm = getActivity().getPackageManager();
boolean isBT = pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
boolean isBLE = pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE);

После этого, используя флаги isBT или isBLE, поток приложения может быть направлен.

1 голос
/ 28 мая 2014
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

// Use this check to determine whether BLE is supported on the device. Then
// you can selectively disable BLE-related features.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
    Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
    finish();
}

http://developer.android.com/guide/topics/connectivity/bluetooth-le.html

0 голосов
/ 12 апреля 2016

Вы просто попробуйте следующий способ найти версию Bluetooth.

AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
    android:name="android.hardware.bluetooth_le"
    android:required="false" />

Запись кода в onCreate ()

public void onCreate(Bundle savedInstanceState) {

    // Use this check to determine whether BLE is supported on the device.  Then you can
    // selectively disable BLE-related features.
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
        //  finish();
    }

    // Initializes a Bluetooth adapter.  For API level 18 and above, get a reference to
    // BluetoothAdapter through BluetoothManager.
    final BluetoothManager bluetoothManager =
            (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothAdapter = bluetoothManager.getAdapter();

    // Checks if Bluetooth is supported on the device.
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show();
        // finish();
        return;
    }
}

Запись кода в onResume ()

protected void onResume() {
    mLeDeviceListAdapter = new LeDeviceListAdapter();
    setListAdapter(mLeDeviceListAdapter);
}

Адаптер

// Adapter for holding devices found through scanning.
private class LeDeviceListAdapter extends BaseAdapter {
    private ArrayList<BluetoothDevice> mLeDevices;

    private LayoutInflater mInflator;

    public LeDeviceListAdapter() {
        super();
        //mLeDevices = new ArrayList<BluetoothDevice>();

        mInflator = DeviceScanActivity.this.getLayoutInflater();
    }

    public void addDevice(BluetoothDeviceModel device, int rssiValue, String address) {

       Log.d("TAG", "map size is : " + mapBluetoothDevice.size());
    }



    public List<BluetoothDevice> getDevice(int position) {
        return mLeDevices.get(position);
    }

    public void clear() {
        mLeDevices.clear();
    }

    @Override
    public int getCount() {
        return mLeDevices.size();
    }

    @Override
    public Object getItem(int i) {

        return mLeDevices.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }


    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        // General ListView optimization code.
        if (view == null) {
            view = mInflator.inflate(R.layout.listitem_device, null);
            viewHolder = new ViewHolder();
            viewHolder.deviceAddress = (TextView) view.findViewById(R.id.device_address);
            viewHolder.deviceName = (TextView) view.findViewById(R.id.device_name);
            viewHolder.deviceRssi = (TextView) view.findViewById(R.id.device_rssi);
            viewHolder.deviceDistance = (TextView) view.findViewById(R.id.device_distance);

            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        BluetoothDevice device = mLeDevices.get(i);

        final String deviceName = device.getName();

        if (deviceName != null && deviceName.length() > 0)
            viewHolder.deviceName.setText(deviceName);
        else
            viewHolder.deviceName.setText(R.string.unknown_device);

        viewHolder.deviceRssi.setText("Version : " + device.getVersion());
        viewHolder.deviceAddress.setText(device.getDevice().getBluetoothAddress());

        }

        viewHolder.deviceDistance.setText("Distance : " + String.valueOf(distance));
        return view;
    }

Это базовое кодирование при взаимодействии с Bluetooth.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...