Android Can';无法使用altbeacon库找到beacon

Android Can';无法使用altbeacon库找到beacon,android,ibeacon-android,altbeacon,beacon,Android,Ibeacon Android,Altbeacon,Beacon,Ì我试图在我的android应用程序中连接信标。但我似乎找不到我的信号灯。我正在使用Ibeacons。我正在使用AltBeacon图书馆。onBeaconServiceConnect启动,随后是DidDeterminateStateForRegion。但迪登雷恩从未接到过电话。这是我的代码: public class ListScenarios extends AppCompatActivity implements BeaconConsumer, MonitorNotifier { priv

Ì我试图在我的android应用程序中连接信标。但我似乎找不到我的信号灯。我正在使用Ibeacons。我正在使用AltBeacon图书馆。onBeaconServiceConnect启动,随后是DidDeterminateStateForRegion。但迪登雷恩从未接到过电话。这是我的代码:

public class ListScenarios extends AppCompatActivity implements BeaconConsumer, MonitorNotifier {

private static final String TAG = "ListScenarios";

private ListView listView;
public String persoonID;
public String adresID;

public Array beaconArray;
//private ArrayList<IBeacon> arrBeacons = new ArrayList<>();

private BeaconManager mBeaconManager;


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

    // Setup beaconmanager
    mBeaconManager = BeaconManager.getInstanceForApplication(this.getApplicationContext());
    // Detect iBeacon
    mBeaconManager.getBeaconParsers().add(new BeaconParser()
            .setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
    mBeaconManager.bind(this);



    //listview
    listView = (ListView) findViewById(R.id.list_scenario);

    //send request to load list
    getScenarios();
    getBeacons();



}


// MARK: - Bluetooth


@Override
public void onBeaconServiceConnect() {
    System.out.println("We are in onBeaconServiceConnect");
    // Set the two identifiers below to null to detect any beacon regardless of identifiers
    Identifier myBeaconNamespaceId = null;
    Identifier myBeaconInstanceId = null;
    Region region = new Region("my-beacon-region", myBeaconNamespaceId, myBeaconInstanceId, null);
    mBeaconManager.addMonitorNotifier(this);
    try {
        mBeaconManager.startMonitoringBeaconsInRegion(region);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

public void didEnterRegion(Region region) {
    System.out.println("We are in didEnterRegion");
    Log.d(TAG, "I detected a beacon in the region with namespace id " + region.getId1() +
            " and instance id: " + region.getId2());
}

public void didExitRegion(Region region) {
    System.out.println("We are in didExitRegion");
}

public void didDetermineStateForRegion(int state, Region region) {
    System.out.println("We are in didDetermineStateForRegion");
}

@Override
public void onPause() {
    super.onPause();
    mBeaconManager.unbind(this);
}
公共类ListScenarios扩展AppCompativeActivity实现Beaconsumer、MonitorNotifier{
私有静态最终字符串TAG=“ListScenarios”;
私有列表视图列表视图;
公共字符串persoonID;
公共字符串地址;
公共阵列信标阵列;
//private ArrayList arrBeacons=new ArrayList();
私人信标管理人;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.list_场景);
//设置信标管理器
mBeaconManager=BeaconManager.getInstanceForApplication(this.getApplicationContext());
//检测iBeacon
mBeaconManager.getBeaconParsers().add(新的BeaconParser())
.setBeaconLayout(“m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25”);
mBeaconManager.bind(这个);
//列表视图
listView=(listView)findViewById(R.id.list\u场景);
//向加载列表发送请求
getScenarios();
getBeacons();
}
//马克:-蓝牙
@凌驾
beacerviceconnect()上的公共无效{
System.out.println(“我们在onBeaconServiceConnect”);
//将下面的两个标识符设置为null以检测任何信标,而不考虑标识符
标识符myBeaconNamespaceId=null;
标识符myBeaconInstanceId=null;
Region Region=新区域(“我的信标区域”,myBeaconNamespaceId,myBeaconInstanceId,null);
mBeaconManager.addMonitorNotifier(此);
试一试{
MBeAconsisten区域(区域)启动监控Beaconsisten经理;
}捕获(远程异常){
e、 printStackTrace();
}
}
公共区域(区域){
System.out.println(“我们在迪登特地区”);
Log.d(标记“我在命名空间id为”+region.getId1()的区域中检测到一个信标)+
实例id:“+region.getId2());
}
公共区域(区域){
System.out.println(“我们在didExitRegion”);
}
公共无效不确定地区(国际州、地区){
System.out.println(“我们在DidDeterministateForRegion”);
}
@凌驾
公共无效暂停(){
super.onPause();
mBeaconManager.unbind(此);
}
需要检查两件事:

  • 确保您使用的是正确的
    BeaconParser
    表达式。问题中显示的表达式适用于AltBeacon:
    “m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25
    。如果您试图检测iBeacon,则需要使用其他表达式。此网站有一个方便的参考:

  • 如果您在Android 6+上运行应用程序,并且目标是SDK 23或更高版本,则需要动态请求应用程序的位置权限。如果不这样做,您将不会得到任何检测,您将在日志中看到:
    04-22 22:35:20.152 5158 5254 E BluetoothUtils:权限拒绝:需要访问\u位置或访问_获取扫描结果的精细位置权限
    您可以在此处阅读如何执行此操作:


  • 你能用基于同一库的定位应用程序检测到信标吗?。你从
    dideterministateforregion
    中的
    state
    值得到了什么?是的,我可以用定位应用程序找到它。它总是说0很高兴听到你修复了它!