1

コードピン付きBluetooth

やあみんな、私がやっているプログラムに問題があります。2 台の Bluetooth デバイスをペアリングし、PIN を入力するメッセージを表示したい。誰かが私を助けることができますか?どうもありがとうございました。よろしく

これは私のコードです:

 private void getPairedDevices() {
    Set<BluetoothDevice> pairedDevice = bluetoothAdapter.getBondedDevices();            
    if(pairedDevice.size()>0)
    {
        for(BluetoothDevice device : pairedDevice)
        {
            arrayListpaired.add(device.getName()+"\n"+device.getAddress()+ "\n DescContents: " + device.describeContents()
                     + "\n BondState: " + device.getBondState()  
                     + "\n HashCode: " + device.hashCode()  
                     + "\n toString: " + device.toString()  
                     + "\n Class: " + device.getClass()   
                     + "\n Uuids: " + device.getUuids()
                     + "\n BTClass: " + device.getBluetoothClass()
                     + "\n   "
                     );
            arrayListPairedBluetoothDevices.add(device);
        }
    }
    adapter.notifyDataSetChanged();
}
class ListItemClicked implements OnItemClickListener
{
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        String ACTION_PAIRING_REQUEST = "android.bluetooth.device.action.PAIRING_REQUEST";
        Intent intent = new Intent(ACTION_PAIRING_REQUEST);
        String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE";
        String device = null;
        intent.putExtra(EXTRA_DEVICE, device);
        String EXTRA_PAIRING_VARIANT = "android.bluetooth.device.extra.PAIRING_VARIANT";
        int PAIRING_VARIANT_PIN = 10;
        intent.putExtra(EXTRA_PAIRING_VARIANT, PAIRING_VARIANT_PIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        Boolean isBonded = false;
        try {
            isBonded = createBond(bdDevice);
            if(isBonded)
            {
                getPairedDevices();
                adapter.notifyDataSetChanged();
            }
        } catch (Exception e) {
            e.printStackTrace(); 
        }
        Log.i("Log", "The bond is created: "+isBonded);
    }       
}
4

0 に答える 0