android10蓝牙搜不到ble设备_android studio 中蓝牙BLE设备搜索

在Android Studio中,使用相同代码进行蓝牙BLE设备搜索时,LeScanCallback的onLeScan方法未被调用。尽管权限已添加,可能需要检查其他配置。示例代码展示了如何在Blues类中初始化并调用扫描方法,以及在MainActivity中实现回调接口。
摘要由CSDN通过智能技术生成

同样的代码在eclipse下能执行LeScanCallback的onLeScan方法 而到了android studio 中就不执行了 权限都加了,是不是android studio中还有配置别的东西?

public class Blues {

Context con;

Blues.M_LeScanCallback_interface callback_interface;

private BluetoothAdapter mBluetoothAdapter;

private LeScanCallback mLeScanCallback = new LeScanCallback() {

public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {

Blues.this.callback_interface.get_address(device.getAddress());

}

};

public Blues(Context con, Blues.M_LeScanCallback_interface callback_interface) {

//在eclipse中 就加执行到这里 在android studio中就不会

BluetoothManager bluetoothManager = (BluetoothManager)con.getSystemService("bluetooth");

this.mBluetoothAdapter = bluetoothManager.getAdapter();

this.con = con;

this.callback_interface = callback_interface;

}

public void scanLeDevice(boolean enable) {

if(enable) {

this.mBluetoothAdapter.startLeScan(this.mLeScanCallback);

} else {

this.mBluetoothAdapter.stopLeScan(this.mLeScanCallback);

}

}

public interface M_LeScanCallback_interface {

void get_address(String var1);

}

}

//下面是activity中的调用

public class MainActivity extends Activity implements Blues.M_LeScanCallback_interface {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

@Override

protected void onResume() {

super.onResume();

Blues blues = new Blues(this, this);

blues.scanLeDevice(true);

}

@Override

public void get_address(String str) {

Toast.makeText(getApplicationContext(), "" + str, Toast.LENGTH_SHORT).show();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值