没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论








android实现蓝牙实现蓝牙app代码代码
主要为大家详细介绍了android实现蓝牙app的代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了android实现蓝牙app的具体代码,供大家参考,具体内容如下
private BluetoothGatt bluetoothGatt;
private BluetoothGattService gattService;
private BluetoothGattCharacteristic gattCharacteristic;
private BluetoothManager bluetoothManager;
private BluetoothAdapter bluetoothAdapter;
private List<BluetoothDevice> devices = new ArrayList<>();
private UUID serviceUUID; //不同设备 不同uuid
private UUID characteristicUUID; //不同设备 不同uuid
private final UUID service4UUID= UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb");
private final UUID charAUUID = UUID.fromString("0000fffa-0000-1000-8000-00805f9b34fb");
private LightReceiver lightReceiver;
private ScanReceiver scanReceiver;
private ListView listView;
private TextView tvrefresh;
private String lightAction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("tag", "MainActivity onCreate()");
//
listView = (ListView) findViewById(R.id.lv_bluetooth);
tvrefresh = (TextView) findViewById(R.id.tv_refresh_bluetooth);
tvrefresh.setOnClickListener(this);
openBluetooth();
registeLigthReceiver();
registeScanReceiver();
}
@Override
protected void onStart() {
super.onStart();
Log.i("tag", "MainActivity onStart()");
bluetoothScan();
}
//返回
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
Log.i("tag", "MainActivity onKeyUp()");
this.finish();
return super.onKeyUp(keyCode, event);
}
//重新扫描蓝牙
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.tv_refresh_bluetooth:
//蓝牙扫描
bluetoothScan();
break;
default:
break;
}
}
//打开本地蓝牙
private void openBluetooth() {
Log.i("tag", "openLocalBluetooth()");
//检查手机是否支持蓝牙4.0
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Toast.makeText(this, "手机不支持蓝牙4.0", Toast.LENGTH_SHORT).show();
finish();
}
//调用系统服务的方式,请求开启蓝牙
bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
bluetoothAdapter = bluetoothManager.getAdapter();
//开启蓝牙
资源评论


weixin_38562725
- 粉丝: 3
- 资源: 932
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
