Android 信标库的信标发射器中的错误代码 2

Error code 2 in beacon transmitter for Android Beacon library

我想使用 Android 信标库发送 BLE 广告。下面是我为此使用的代码。

package com.example.beacon_emitter;

import java.util.Arrays;

import org.altbeacon.beacon.Beacon;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.BeaconTransmitter;

import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.bluetooth.le.AdvertiseCallback;
import android.bluetooth.le.AdvertiseSettings;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;


public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Beacon beacon  = new Beacon.Builder()
        .setId1("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6")
        .setId2("1")
        .setId3("2")
        .setManufacturer(0x0118)
        .setTxPower(-59)
        .setDataFields(Arrays.asList(new Long[] {0l}))
        .build();
        BeaconParser beaconParser = new BeaconParser()
        .setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
        BeaconTransmitter beaconTransmitter = new BeaconTransmitter(getApplicationContext(), beaconParser); 
        beaconTransmitter.startAdvertising(beacon,new AdvertiseCallback() {
            @Override
            public void onStartFailure(int errorCode) {
                Log.e("beacon", "Advertisement start failed with code: "+errorCode);
            }

            @Override
            public void onStartSuccess(AdvertiseSettings settingsInEffect) {
                Log.i("beacon", "Advertisement start succeeded.");
            }
        });

        int result = BeaconTransmitter.checkTransmissionSupported(getApplicationContext());
        Toast.makeText(this, "Device info " + result, Toast.LENGTH_LONG).show();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

它总是给我一个错误代码 2,ADVERTISE_FAILED_TOO_MANY_ADVERTISERS。但奇怪的是,当我检查 toast 消息时,它说我的设备支持信标传输。我很迷惑。

请帮忙!

提前致谢。

几点提示:

  1. BeaconTransmitter.checkTransmissionSupported() 方法只检查设备是否有蓝牙 LE,操作系统会给你一个 BluetoothAdvertiser

  2. 要查看其他人是否已成功让您的设备进行传输,请查看它是否在此列表中:http://altbeacon.github.io/android-beacon-library/beacon-transmitter-devices.html

  3. ADVERTISE_FAILED_TOO_MANY_ADVERTISERS 响应可以指示另一个应用程序正在广告信标,并且所有广告位都已使用。确保您没有任何其他应用程序在后台播放广告。如有必要,请重新启动或卸载可能正在执行此操作的其他应用程序。

  4. 试试基于同一个库的Locate Beacon app,看看它是否能成功发布信标。这将消除您的代码可能出现的任何问题。

编辑: 根据下面的评论,可以合理地得出结论,Intrynsyc 评估套件的固件没有正确实现 Android 和蓝牙芯片。否则它要么报告广告不可用,要么在开始广告时不会 return 出现错误消息。适当的下一步是打开 Intrynsyc 的问题并报告这些发现。

The ability to transmit as a beacon requires Bluetooth LE advertisement capability, which may or may not be supported by a device’s firmware.

引用自Device Support For Beacon Transmission with Android 5+