android怎么隐藏蓝牙,Android提高之探秘蓝牙隐藏API

private BroadcastReceiver searchDevices = new BroadcastReceiver() {

public void onReceive(Context context, Intent intent) {

String action = intent.getAction();

Bundle b = intent.getExtras();

Object[] lstName = b.keySet().toArray();

// 显示所有收到的消息及其细节

for (int i = 0; i < lstName.length; i++) {

String keyName = lstName[i].toString();

Log.e(keyName, String.valueOf(b.get(keyName)));

}

// 搜索设备时,取得设备的MAC地址

if (BluetoothDevice.ACTION_FOUND.equals(action)) {

BluetoothDevice device = intent

.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

if (device.getBondState() == BluetoothDevice.BOND_NONE) {

String str = "未配对|" + device.getName() + "|" + device.getAddress();

lstDevices.add(str); // 获取设备名称和mac地址

adtDevices.notifyDataSetChanged();

}

}

}

};

class ItemClickEvent implements AdapterView.OnItemClickListener {

@Override

public void onItemClick(AdapterView> arg0, View arg1, int arg2,

long arg3) {

btAdapt.cancelDiscovery();

String str = lstDevices.get(arg2);

String[] values = str.split("\\|");

String address=values[2];

btDevice = btAdapt.getRemoteDevice(address);

try {

if(values[0].equals("未配对"))

{

Toast.makeText(testReflect.this, "由未配对转为已配对", 500).show();

ClsUtils.createBond(btDevice.getClass(), btDevice);

}

else if(values[0].equals("已配对"))

{

Toast.makeText(testReflect.this, "由已配对转为未配对", 500).show();

ClsUtils.removeBond(btDevice.getClass(), btDevice);

}

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

/**

* 按键处理

* @author GV

*

*/

class ClickEvent implements View.OnClickListener {

@Override

public void onClick(View v) {

if (v == btnSearch) {//搜索附近的蓝牙设备

lstDevices.clear();

Object[] lstDevice = btAdapt.getBondedDevices().toArray();

for (int i = 0; i < lstDevice.length; i++) {

BluetoothDevice device=(BluetoothDevice)lstDevice[i];

String str = "已配对|" + device.getName() + "|" + device.getAddress();

lstDevices.add(str); // 获取设备名称和mac地址

adtDevices.notifyDataSetChanged();

}

// 开始搜索

setTitle("本机蓝牙地址:" + btAdapt.getAddress());

btAdapt.startDiscovery();

}

else if(v==btnShow){//显示BluetoothDevice的所有方法和常量,包括隐藏API

ClsUtils.printAllInform(btDevice.getClass());

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值