=開発環境=
Eclipse 4.2.1
ADT 23.0.2.1259578
開発対象SDK 5.0.1
=実機の環境=
SH-02E Android4.1.2
Nexus7(2012) Android 5.0.2
AST21 Android4.4.2
です。
BluetoothChatアプリケーションを
編集して自動ペアリングを目指していますが、
うまくいきません。
ビルドは成功して実機でも起動しますが、
自動ペアリングはうまくいきませんでした。
更に、実機でのデバッグをして、
setPin createBondメソッドが、
読みだされ、boolean型でtrueで帰ってきているのですが、
自動ペアリングはできませんでした。
どなたか、わかる方がいましたら回答、よろしくお願いします。
ソースコードを以下に記述します。
(BluetoothChatのBluetoothChat.javaファイルです)
lang
1 private void connectDevice(Intent data, boolean secure) { 2 String address = data.getExtras() 3 .getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); 4 BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); 5 try { 6 Method createBondMethod = device.getClass().getMethod("createBond", (Class[]) null); 7 Boolean result = (Boolean)createBondMethod.invoke(device); 8 Method convertPinToBytesMethod = BluetoothDevice.class.getMethod("convertPinToBytes", new Class[]{ String.class }); 9 byte[] pinCodes = (byte[])convertPinToBytesMethod.invoke(BluetoothDevice.class, "0000"); 10 Method setPinMethod = device.getClass().getMethod("setPin", new Class[]{ byte[].class }); 11 Boolean success =(Boolean)setPinMethod.invoke(device, pinCodes); 12 } catch (Exception e) { 13 Log.e("pairDevice()", e.getMessage()); 14 } 15 16 }
あなたの回答
tips
プレビュー