标签: android-bluetooth

Android 中的 MAC 地址是否会随时间变化

您好,我想获取 android 设备的 MAC 地址,因此有两种使用方式WiFiBlueTooth适配器方式。

请问,当你打开/关闭在此时间MAC地址更改WiFiBlueTooth或重新启动设备或恢复出厂设置。任何的想法 ?

android bluetooth android-wifi android-bluetooth

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

如何在Android上读取蓝牙的InputStream

我正在尝试测试PC 和 Android 手机之间的蓝牙通信示例。我的 SPP 客户端正是来自那里的客户端,并且运行良好。我是 Android 新手,我不想让它在单独的线程中运行,因为我不知道如何运行,所以我只是在方法中完成了所有操作onCreate()。如果这不是最好的方法,请随时为我指出更好的方法,但这不是我的主要问题。

问题是我想在 a 上显示通过蓝牙收到的文本textView,但我不知道如何读取InputStream. 当代码像这样留下时,它会显示类似java.io.DataInputStream@41b0cb68 我尝试过的内容,就像这里它没有显示任何内容,而且我不知道正在使用什么编码。

这是我的 Android 应用程序的代码:

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;

import android.app.Activity;
import android.bluetooth.*;
import android.util.Log;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MainActivity extends Activity {

//based on java.util.UUID
private static UUID MY_UUID = UUID.fromString("446118f0-8b1e-11e2-9e96-0800200c9a66");

// The local server socket
private BluetoothServerSocket mmServerSocket;

// based …
Run Code Online (Sandbox Code Playgroud)

io android bluetooth inputstream android-bluetooth

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

无需用户确认即可发现蓝牙

在 Android 中,有 enable() 方法似乎无需用户确认即可启用蓝牙。我想知道是否有一种方法可以在没有用户确认的情况下以编程方式启用可发现性?

非常感谢

android android-bluetooth

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

扫描过滤器的Android蓝牙低功耗扫描问题

当我尝试在棒棒糖中使用BleScan中的ScanFilter时,它不是扫描设备(仅当我通过ScanFilter列表时).如果我只通过一个UUID它的工作正常.但在多数的情况下它不工作..

 ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_BALANCED).build();
        if (getBluetoothStatus()) {
            mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
            List<ScanFilter> mList=scanFilters(serviceUUIDs);
            mBluetoothLeScanner.startScan(mList, settings, mScanCallback);

        }



     private List<ScanFilter> scanFilters(UUID[] serviceUUIDs) {
                List<ScanFilter> list = new ArrayList<>();
                for (int i = 0; i <serviceUUIDs.length; i++) {
                ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(serviceUUIDs[0].toString())).build();

                    list.add(filter);
                }

          return list;
            }
Run Code Online (Sandbox Code Playgroud)

android bluetooth-lowenergy android-bluetooth

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

如何识别Eddystone URL和uid?

我希望在不使用 Proximity Beacon API 或附近消息 API 的情况下检测 Eddystone Ul 和 uid。我希望使用原生 Android 库(如 BluetoothAdapter、BluetoothGatt 或 BluetoothGap)来解析 eddystone 帧。这可行吗?如果是的话,如何进行?如果不可行,那么还有什么替代方案?

android bluetooth-lowenergy android-bluetooth ibeacon-android eddystone

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

什么是主机和控制器 btsnoop_hci.log?

在 btnsnoop_hci.log 文件中,我对主机、控制器、remote() 和 LocalHost() 有点困惑。我在谷歌上挖掘以理解但无法找到解释它的正确文档。如果您对 btnsnoop_hei.log 有任何想法,请分享。

android bluetooth-lowenergy android-bluetooth

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

使用BluetoothManager和getAdapter()

我正在 Kotlin 中开发 Android 应用程序,我正在尝试在我的应用程序中获取用于蓝牙通信的蓝牙适配器。

我已阅读此文档:设置蓝牙

如图所示,我需要编写以下代码来获取适配器:

val bluetoothAdapter: BluetoothAdapter? = BluetoothAdapter.getDefaultAdapter()
if (bluetoothAdapter == null) {
  // Device doesn't support Bluetooth
}
Run Code Online (Sandbox Code Playgroud)

当我在 Android Studio 中编写此内容时,我收到以下警告:

'getDefaultAdapter(): BluetoothAdapter!' is deprecated. Deprecated in Java
...
Deprecated: this method will continue to work, but developers are 
strongly encouraged to migrate to using BluetoothManager.getAdapter(), since that 
approach enables support for Context.createAttributionContext.
Run Code Online (Sandbox Code Playgroud)

我尝试使用像这样的新推荐方式

var bluetoothManager = (BluetoothManager)(Context.getSystemService(Context.BLUETOOTH_SERVICE))
var adapter = bluetoothManager.getAdapter()
Run Code Online (Sandbox Code Playgroud)

我在代码中收到此错误:

Unresolved reference: getSystemService
Run Code Online (Sandbox Code Playgroud)

我尝试了多种方法来实现它 - 没有任何效果。

我很乐意得到一些帮助。

请指教。

谢谢

android bluetooth kotlin android-studio android-bluetooth

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

无法从BLE设备接收数据

我又来了。
因此,长话短说:在我的应用程序中,我正在尝试借助Android Samples(that)从BLE设备(壁垒心率监视器:that)接收数据。但是...我没有从我的设备接收数据!我可以得到特征和描述符,但是……仅此而已。我只是.. 错过了重点。这是我的代码:

private BluetoothLeService mBluetoothLeService;
private ArrayList<BluetoothGattCharacteristic> mGattCharacteristics =
        new ArrayList<BluetoothGattCharacteristic>();
private BluetoothGattCharacteristic mNotifyCharacteristic;
public static final String EXTRAS_DEVICE_NAME = "DEVICE_NAME";
public static final String EXTRAS_DEVICE_ADDRESS = "DEVICE_ADDRESS";
private static final int CONNECTED_ID = 1;
private String mDeviceName;
private String mDeviceAddress;
private boolean mConnected = false;
BluetoothGatt btGatt;
BluetoothGattCharacteristic btGattCharacteristic;
 private List<BluetoothGattCharacteristic> gattCharacteristics = new ArrayList<BluetoothGattCharacteristic>();
    @InjectView(R.id.hrate) public TextView hRate;
private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, …
Run Code Online (Sandbox Code Playgroud)

java android bluetooth-lowenergy android-bluetooth

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

如何等到蓝牙在android中打开

我需要以编程方式打开Android设备中的蓝牙并等到它继续进行下一行代码.

我的代码如下

if (!mBluetoothAdapter.isEnabled()) {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                ctx.startActivity(enableBtIntent);
}
Run Code Online (Sandbox Code Playgroud)

当这样做时,代码继续从nect行执行,而不必完全等待蓝牙.有什么方法可以解决这个问题吗?我可以添加外观来检查蓝牙是否已打开?

android android-bluetooth

3
推荐指数
2
解决办法
3771
查看次数

Android BLE Gatt连接更改状态

我有一个Android应用程序连接到BLE设备并写入它.我可以成功连接,读取和写入它.作为测试的一部分,我们正在尝试不同的断开连接.

有时,如果ble设备断开连接,我将连接更改为断开连接,状态值为19.此外,如果存在任何绑定错误,则状态等于22.如果我以编程方式断开连接,则此状态为0.但没有除了0之外的这些状态在android文档中指定.

发布示例BluetoothGattCallback

private BluetoothGattCallback bluetoothGattCallback = new BluetoothGattCallback() {
    @Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
        Log.i(TAG, "onConnectionStateChange status: "+status+", newState: "+newState);
        /*i need to know the posiible values for this status variable*/
        if(newState == BluetoothProfile.STATE_CONNECTED) {
            gatt.discoverServices();
        } else {
            gatt.close();
        }
    }

    @Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        Log.i(TAG, "onServicesDiscovered service discovered");
    }
};
Run Code Online (Sandbox Code Playgroud)

有没有人遇到同样的问题,并整理出状态列表.我需要知道onConnectionStateChange方法中状态变量的可能值

android bluetooth android-bluetooth android-ble bluetooth-gatt

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