【发布时间】:2014-04-28 11:47:50
【问题描述】:
当我的课程被加载时,我会不断收到NoClassDefFoundError。
代码取自 BluetoothLeGatt 项目 -
http://developer.android.com/samples/BluetoothLeGatt/project.html
我的代码:
// Device scan callback.
private BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() { //java.lang.NoClassDefFoundError...
@Override
public void onLeScan(final BluetoothDevice device,
final int rssi, final byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
String msg= device.getAddress();
Log.d(TAG,msg);
addItems(msg);
}
});
}
};
有人建议该错误是因为我的设备不支持 BLE,但我想为任何设备消除此错误。因此,如果它不支持 BLE 功能,则只需跳过此错误,否则继续调用此 BluetoothAdapter.LeScanCallback。
注意:
请参阅this我以前的 SO 帖子以获得更多说明。
将 BLE 功能检查作为第一行 onCreate() 并不能阻止崩溃 --
@Override
public void onCreate(Bundle savedInstanceState) {
if (!bleCheck()) {
Toast.makeText(getApplicationContext(), R.string.ble_not_supported,
Toast.LENGTH_SHORT).show();
finish();
}
//Rest of the code
//Call to BLE Scan on button click that causes error..
}
private boolean bleCheck() {
boolean result = false;
if (getPackageManager().
hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)){
result = true;
}
return result;
}
【问题讨论】:
-
希望答案对您有所帮助,Android 的 BLE 目前还很棘手,一直在努力
标签: android bluetooth-lowenergy android-bluetooth