[英]How to access value of an extra
我想訪問BluetoothDevice.ACTION_FOUND中包含的其他內容,例如,如果我想訪問BluetoothDevice.EXTRA_CLASS中包含的值,則應按以下代碼所示使用它,但是當我顯示變量“ state”的值時“,它就像-245175
BluetoothDevice.EXTRA_CLASS內部是否還有其他值可續? 我怎么知道他們? 我應該如何訪問它們?
更新 :
我注冊的意圖是: BluetoothDevice.ACTION_FOUND
代碼 :
switch (action) {
case BluetoothDevice.ACTION_FOUND:
Log.d(TAG, LogAnd.i("onReceive", "BluetoothDevice.ACTION_FOUND"));
final int state = intent.getIntExtra(BluetoothDevice.EXTRA_CLASS, BluetoothAdapter.ERROR);
Log.d(TAG, LogAnd.i("onReceive", "state: "+state));
break;
您正在使用getIntExtra()
,但是額外的值不是整數。 它仍然是“有效的”,但是內容以錯誤的方式解釋,因此您獲得了毫無意義的價值。
在ACTION_FOUND和ACTION_CLASS_CHANGED意圖中用作Parcelable
BluetoothClass
額外字段。
您應該改用getParcelableExtra()
。 那應該給你一個正確的類的實例。 像這樣:
BluetoothClass bclass = (BluetoothClass)intent.getParcelableExtra(BluetoothDevice.EXTRA_CLASS);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.