没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Android基于基于ibeacon实现蓝牙考勤功能实现蓝牙考勤功能
主要为大家详细介绍了Android基于ibeacon实现蓝牙考勤功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
说明:说明:
ibeacon设备会主动发射蓝牙信号,当手机打开蓝牙靠近ibeacon设备时,就会收到设备发送的蓝牙信号,这时只需要根据ibeacon设备的uuid、major、
minor、mac这四个值,就可以确认是哪一台ibeacon设备,然后调用服务端考勤接口(ibeacon设备只为了确认手机在考勤机边上,不需要发送考勤数据到
ibeacon设备上),即可实现蓝牙考勤。
一、添加静态权限一、添加静态权限(在在AndroidManifest.xml文件中添加,需要蓝牙和定位权限文件中添加,需要蓝牙和定位权限)
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
二、检测与开启蓝牙、二、检测与开启蓝牙、GPS
1.是否支持蓝牙:
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
ToastUtils.show("本机不支持蓝牙功能, 无法蓝牙打卡");
((Activity) context).finish();
return false;
}
final BluetoothManager bm = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
mBleAdapter = bm.getAdapter(); //mBleAdapter为全局变量,为BluetoothAdapter对象
}
if (bleAdapter == null) {
ToastUtils.show("本机不支持低功耗蓝牙功能, 无法蓝牙打卡");
((Activity) context).finish();
return false;
}
return true;
2.是否开启GPS:
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
boolean gps = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean network = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (gps || network) {
return true;
}
return false;
3.开启GPS:
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
context.startActivityForResult(intent, ActivityCode.ACTIVITY_CODE_GPS);
4.开启蓝牙:
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
((Activity) mContext).startActivityForResult(enableBtIntent, ActivityCode.ACTIVITY_CODE_OPEN_BLE);
三、动态申请蓝牙权限三、动态申请蓝牙权限
private boolean check(Context context, String permission) {
return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
}
/**
* 权限申请
*/
private void searchBle(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!check(mContext, Manifest.permission.ACCESS_FINE_LOCATION) || !check(mContext, Manifest.permission.ACCESS_COARSE_LOCATION)) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, ACCESS_LOCATION);
} else {
//执行蓝牙搜索
}
} else {
//执行蓝牙搜索
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case ACCESS_LOCATION:
if (hasAllPermissionsGranted(grantResults)) {
//执行蓝牙搜索
} else {
ToastUtils.show("请开启权限");
}
break;
}
}
四四.搜索蓝牙搜索蓝牙
资源评论
weixin_38631225
- 粉丝: 5
- 资源: 909
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功