在华硕、三星平板电脑上出现错误,操作系统版本为 4.4.2 Android 信标库版本。
得到以下问题。
我尝试更新库,处理崩溃,但仍然能够看到以下错误:-
java.lang.NoSuchMethodError: android.bluetooth.BluetoothAdapter.getBluetoothLeAdvertiser at org.altbeacon.beacon.g.(Unknown Source) at com.mangomirror.app.activity.ab(Unknown Source) at com.mangomirror.app.activity.HomeActivity $2.a(Unknown Source) at dg$a$1$1.run(Unknown Source) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) 在 android.app.ActivityThread.main(ActivityThread.java:5001) 在 java.lang.reflect.Method.invokeNative(Native Method) 在 java.lang.reflect。 Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)在 dalvik.system.NativeStart.main(本机方法)
以下是我的代码: -
public void broadcastAsBeacon(int major, int minor) {
Beacon beacon = new Beacon.Builder()
.setId1("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6")
.setId2(String.valueOf(major))
.setId3(String.valueOf(minor))
.setManufacturer(0x004C)
.setTxPower(txPower)
.setRssi(-89)
.setDataFields(Arrays.asList(new Long[]{0l}))
.build();
BeaconParser beaconParser = new BeaconParser()
.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");//
try {
beaconTransmitter = new BeaconTransmitter(this, beaconParser);
}catch(Exception e){
Log.i("TAG", String.valueOf(e));
}
if (beaconTransmitter!=null) {
beaconTransmitter.startAdvertising(beacon, new AdvertiseCallback() {
@Override
public void onStartFailure(int errorCode) {
Log.e("Class", "Advertisement start failed with code: " + errorCode);
}
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
Log.i("class", "Advertisement start succeeded." + settingsInEffect.getTxPowerLevel());
Log.i("class", "Advertisement start succeeded." + settingsInEffect);
}
});
}
}
private boolean isBleEnabled() {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
// Device does not support Bluetooth
} else {
if (bluetoothAdapter!=null) {
if (!bluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BLE);
return false;
}
}
}
return true;
}