适用于Android Beacon库的Beacon发送器中的错误代码2 [英] Error code 2 in beacon transmitter for Android Beacon library

查看:183
本文介绍了适用于Android Beacon库的Beacon发送器中的错误代码2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Android信标库发送BLE广告.下面是我正在使用的代码.

I want to send a BLE advertisement using Android beacon library. Below is the code I am using for it.

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消息时,它说我的设备支持信标传输.我很迷惑.

It always gives me an errorcode 2, ADVERTISE_FAILED_TOO_MANY_ADVERTISERS. But the strange thing is when I checked the toast message it says the my device is supported the beacon transmission. I am confused.

请帮助!

预先感谢.

推荐答案

一些提示:

  1. BeaconTransmitter.checkTransmissionSupported()方法仅检查设备是否具有Bluetooth LE,并且操作系统将为您提供BluetoothAdvertiser.

  1. The BeaconTransmitter.checkTransmissionSupported() method only checks to see if the device has Bluetooth LE and that the operating system will give you a BluetoothAdvertiser.

要查看是否有人成功使您的设备进行传输,请检查它是否在此列表中:

To see if somebody else has been successful with getting your device to transmit, check to see if it is on this list: http://altbeacon.github.io/android-beacon-library/beacon-transmitter-devices.html

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

The ADVERTISE_FAILED_TOO_MANY_ADVERTISERS response can indicate that another app is advertising a beacon, and all the advertisement slots are used. Make sure that you don't have any other apps advertising in the background. Reboot or uninstall other apps that might be doing this if necessary.

尝试找到信标应用基于相同的库,并查看它是否可以成功发布信标.这将消除您的代码的任何可能的问题.

Try the Locate Beacon app which is based on this same library, and see if it can advertise a beacon successfully. This will eliminate any possible problem with your code.

编辑:根据以下评论,可以得出合理的结论,即Intrynsyc评估套件的固件未正确实现Android与蓝牙芯片之间的接口.否则,它会报告广告不可用,或者在开始广告时不会返回错误消息.适当的下一步是与Intrynsyc开一个问题,并报告这些发现.

Based on the comments below, it is reasonable to conclude that the firmware for the Intrynsyc eval kit does not properly implement the interface between Android and the Bluetooth chip. Otherwise it would either report that advertising is not available or it would not return an error message when starting advertising. The appropriate next step would be to open an issue with Intrynsyc and report these findings.

这篇关于适用于Android Beacon库的Beacon发送器中的错误代码2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆