BluetoothChatアプリを使って、
自動ペアリングを行いたいと思っています。
セキュリティ上の問題は、今のところ考えていません。
CreateBond()、SetPinを使って、行おうと、
以下の方法をしているのですが、エラーが、
wifiManeger can not be resolved to a type
The Method createBond() in the type BluetoothDevice is not applicable for the arguments()
The method convertPinToBytes(String) is undefined for the type BluetoothDevice
がでています。
どうすればいいでしょうか
lang
1private final BroadcastReceiver mReceiver = new BroadcastReceiver() { 2@Override 3public void onReceive(Context context, Intent intent) { 4String action = intent.getAction(); 5 6Log.d(TAG, "Action:" + action); 7 8if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) { 9Log.d(TAG, "ACTION_BOND_STATE_CHANGED"); 10BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 11WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); 12WifiInfo wifiInfo = wifiManager.getConnectionInfo(); String macAddress = wifiInfo.getMacAddress(); 13Method createBond = device.getClass().getMethod("createBond", new Class[] {}); 14boolean a = device.createBond(wifiInfo.getMacAddress()); 15boolean b = device.setPin(device.getAddress(), BluetoothDevice.convertPinToBytes("0000")); 16Log.d(TAG, "createBond:" + a + ", setPin:" + b); 17if (a && b) { 18Log.d(TAG, "AutoPairing Success !"); 19} 20}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。