Radius Network Beacon Library 2.0(AltBeacon)无法检测信标

时间:2014-08-20 05:48:40

标签: android ibeacon-android android-ibeacon altbeacon

您好我正在使用Radius Network Beacon SDK,但无法检测到我的信标。 在didRangeBeaconsInRegion(集合信标,Region区域)集合对象大小为0

请帮助我!!

RangingActivity Code -

import java.util.Collection;
import android.app.Activity;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import android.widget.EditText;
import org.altbeacon.beacon.AltBeacon;
import org.altbeacon.beacon.Beacon;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.RangeNotifier;
import org.altbeacon.beacon.Region;

public class RangingActivity extends Activity implements BeaconConsumer {
  protected static final String TAG = "RangingActivity";
private BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);

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

    beaconManager.bind(this);
    beaconManager.debug = true;
}
@Override 
protected void onDestroy() {
    super.onDestroy();
    beaconManager.unbind(this);
}
@Override 
protected void onPause() {
    super.onPause();
}
@Override 
protected void onResume() {
    super.onResume();
}

@Override
public void onBeaconServiceConnect() {
    beaconManager.setRangeNotifier(new RangeNotifier() {
    @Override 
    public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
        if (beacons.size() > 0) {
            EditText editText = (EditText)RangingActivity.this
                    .findViewById(R.id.rangingText);
            Beacon firstBeacon = beacons.iterator().next();
            logToDisplay("The first beacon "+firstBeacon.toString()+" is about "+firstBeacon.getDistance()+" meters away.");
        }
    }



    });

    try {
        beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
        //beaconManager.updateScanPeriods();
    } catch (RemoteException e) {   }
}
private void logToDisplay(final String line) {
    runOnUiThread(new Runnable() {
        public void run() {
            EditText editText = (EditText)RangingActivity.this
                    .findViewById(R.id.rangingText);
            editText.append(line+"\n");             
        }
    });
}

}

2 个答案:

答案 0 :(得分:4)

您需要自定义Parser才能正确识别信标。

看一下这个答案:

Is this the correct layout to detect iBeacons with AltBeacon's Android Beacon Library?

答案 1 :(得分:0)

您需要拨打onBeaconConnect()功能

中的onCreate
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_ranging);

  beaconManager.bind(this);
  beaconManager.debug = true;

  onBeaconConnect()
}