BluetoothChatアプリケーションの自動ペアリングについてです。
ソースを以下のように書いたところ、
起動してデバイスの検索をかけ、ペアリング操作を行おうとすると、PINの要求をされます。
convertPinToBytesMethodでbyte型に数字を変更して、setPinでPINコードを指定して、
createBondで実行しているはずなのですが、要求画面が出てしまいます。
デバッグするとプログラム自体はきちんと読み取っています。
何処が悪いのでしょうか。
lang
1 try { 2 Log.d("pairDevice()", "Start Pairing..."); 3 Method convertPinToBytesMethod = BluetoothDevice.class.getMethod("convertPinToBytes", new Class[]{ String.class }); 4 byte[] pinCodes = (byte[])convertPinToBytesMethod.invoke(BluetoothDevice.class, "0000"); 5 Method setPinMethod = device.getClass().getMethod("setPin", new Class[]{ byte[].class }); 6 Boolean result = (Boolean)setPinMethod.invoke(device, pinCodes); 7 Method m = device.getClass().getMethod("createBond", (Class[]) null); 8 m.invoke(device, (Object[]) null); 9 Log.d("pairDevice()", "Pairing finished."); 10 } catch (Exception e) { 11 Log.e("pairDevice()", e.getMessage()); 12 }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/02/22 08:10