java.lang.NoSuchMethodError:org.altbeacon.beacon上的android.bluetoothAdapter.getBluetoothLeAdvertiser

时间:2019-04-17 06:47:46

标签: advertising altbeacon bluetoothadapter

在华硕,具有4.4.2操作系统版本的三星平板电脑上出现错误 Android Beacon库版本。

获取以下问题。

我尝试更新库,处理了崩溃,但仍然能够看到以下错误:-

  

java.lang.NoSuchMethodError:   android.bluetooth.BluetoothAdapter.getBluetoothLeAdvertiser位于   org.altbeacon.beacon.g。(来源未知)   com.mangomirror.app.activity.a.b(来源未知)   com.mangomirror.app.activity.HomeActivity $ 2.a(来源未知)   d.g $ a $ 1 $ 1.run(来源未知)   android.os.Handler.handleCallback(Handler.java:733)在   android.os.Handler.dispatchMessage(Handler.java:95)在   android.os.Looper.loop(Looper.java:136)在   android.app.ActivityThread.main(ActivityThread.java:5001)在   java.lang.reflect.Method.invokeNative(本机方法)位于   java.lang.reflect.Method.invoke(Method.java:515)在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:785)   在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;
}

1 个答案:

答案 0 :(得分:0)

仅Android 5.0以上版本支持传输。根据库docs,您必须先调用以下命令检查是否支持传输

int result = BeaconTransmitter.checkTransmissionSupported(context);

如果设备支持传输,则该方法返回BeaconTransmitter.SUPPORTED。它也可能返回:

NOT_SUPPORTED_MIN_SDK
NOT_SUPPORTED_BLE
NOT_SUPPORTED_MULTIPLE_ADVERTISEMENTS (deprecated)
NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS
NOT_SUPPORTED_CANNOT_GET_ADVERTISER