2012-02-08 33 views
0

我不覺得很多BluetoothDevice類 methodes如,setPasskey()setPin()setPairingConfirmation()setRemoteOutOfBandData()setPin()顯示在Eclipse錯誤 「setPin()是未定義BluetoothDevice類」

我搜索了Android網站,但我沒有找到它。當我在eclipse中的程序中使用這些方法時,它會向我顯示一個錯誤:它未定義類型BluetoothDevice

現在已經過時了嗎?如果是,那麼相同類型的新方法是什麼。

回答

0

假定配對過程僅由與平臺一起交付的應用程序執行! 這意味着此應用程序可以訪問隱藏的API。例如,您可以找到hidden API for Bluetooth here。 強烈建議不要使用隱藏的API,因爲它可以在未來的Android版本中發生更改而不會發出警告。 如果你仍然打算使用這個API最安全的方法是使用反射:

try { 
    Class<? extends BluetoothDevice> c = device.getClass(); // BluetoothDevice.class 
    Method createBond = c.getMethod("createBond"); 
    Object result = createBond.invoke(device); 
    Boolean castedResult = (Boolean)result; 
    Log.d(TAG, "Result: " + castedResult.toString()); 
} catch (SecurityException e) { 
    e.printStackTrace(); 
} catch (NoSuchMethodException e) { 
    e.printStackTrace(); 
} catch (IllegalArgumentException e) { 
    e.printStackTrace(); 
} catch (IllegalAccessException e) { 
    e.printStackTrace(); 
} catch (InvocationTargetException e) { 
    e.printStackTrace(); 
} 

還有另一種方法easy use hidden API,但我沒有嘗試。

相關問題