java - 如何让 AltBeacon 库的 BootstrapRegion 识别 iBeacon 布局?

标签 java android ibeacon

我正在使用引用,http://altbeacon.github.io/android-beacon-library/samples.html .我也用过 How to detect Region Enter/Exit for multiple beacons using AltBeacon android-beacon-library?

我正在尝试使用 AltBeacon 的 Android-Beacon-Library 在后台检测 iBeacon。我在我的项目中包含了以下代码 fragment 。到目前为止,我没有在后台检测到 ibeacons...感谢任何帮助

我正在使用 BeaconManager

setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));

但是,我没有收到任何错误,也没有信标检测。在 Samsung Galaxy 4 设备上调试运行应用程序时,应用程序启动但未检测到 Activity 信标。我的信标是配置为 iBeacon 的 Rad Beacon。 Rad Beacon 应用程序检测到它们,我在前台运行并检测我的 iBeacon 的其他 AltBeacon 库应用程序也是如此。这些应用程序在 Samsung Galaxy 4 上运行。

我为背景信标检测设置的应用程序...没有检测到 iBeacons。

这是我的代码。对 Constants.java 的引用只是我的应用程序的常量文件。

package com.myApp.BTleDemo;

import android.app.Application;
import android.content.Intent;
import android.util.Log;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;



import org.altbeacon.beacon.startup.BootstrapNotifier;
import org.altbeacon.beacon.startup.RegionBootstrap;
import org.altbeacon.beacon.Region;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.MonitorNotifier;
import org.altbeacon.beacon.RangeNotifier;
import org.altbeacon.beacon.Region;
import org.altbeacon.beacon.Identifier;




public class BackgroundMode extends Application implements BootstrapNotifier{
    private static final String TAG = ".BackgroundMode";
    private RegionBootstrap regionBootstrap;

    private BeaconManager beaconManager;
SharedPreferences prefs;
List<Region> regions;
    public void onCreate() {
        super.onCreate();
    Log.d(TAG, "App started up");


  beaconManager = BeaconManager.getInstanceForApplication(this);
  // Add AltBeacons Parser for iBeacon 
  beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));


    // wake up the app when any beacon is seen (you can specify specific id filers in the parameters below)

  Region region = new Region("com.myApp.BTleDemo.boostrapRegion", Identifier.parse(Constants.BT_UUID), 
  Identifier.fromInt(Constants.BT_MAJOR), Identifier.fromInt(Constants.BT_MINOR));

        regionBootstrap = new RegionBootstrap(this, region);


}


@Override
public void didDetermineStateForRegion(int arg0, Region arg1) {
    // Don't care
}

@Override
public void didEnterRegion(Region arg0) {
    Log.d(TAG, "Got a didEnterRegion call");

    // This call to disable will make it so the activity below only gets launched the first time a beacon is seen (until the next time the app is launched)
    // if you want the Activity to launch every single time beacons come into view, remove this call.  
    regionBootstrap.disable();
    Intent intent = new Intent(this, MainActivity.class);
    // IMPORTANT: in the AndroidManifest.xml definition of this activity, you must set android:launchMode="singleInstance" or you will get two instances
    // created when a user launches the activity manually and it gets launched from here.
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    this.startActivity(intent);
}

@Override
public void didExitRegion(Region arg0) {
    // Don't care
}  


/*
@Override
public void onBeaconServiceConnect() {
    beaconManager.setRangeNotifier(new RangeNotifier() {

    @Override 
    public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
        if (beacons.size() > 0) {
            Log.i(TAG, "The first beacon I see is about "+beacons.iterator().next().getDistance()+" meters away.");     
        }
    }
    });

    try {
        beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
    } catch (RemoteException e) {   }
}
}
*/
}

我没有得到任何 ibeacon 检测。没有发布任何预期的 LogCat 列表。我错过了一些步骤吗?

最佳答案

编辑您的 project.properties 文件并添加以下行:

manifestmerger.enabled=true

在此处查看完整说明:

http://altbeacon.github.io/android-beacon-library/configure.html

该问题与您尝试识别的信标类型无关。如果不启用 list 合并,您的 AndroidManifest.xml 文件就没有从库继承的服务定义来启动 BeaconService,因此不会检测到任何类型的信标。

使用 Eclipse,您可以通过构建来判断 list 合并是否正常工作,然后在 bin/AndroidManifest.xml 中查看生成的 list 。此 list 应包括以下条目。

如果一切都失败了,您可以手动将这些条目复制到您的项目 list 中:

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<!-- nest the entries below underneath your application tag -->

    <service android:enabled="true" android:exported="true" android:isolatedProcess="false" android:label="beacon" android:name="org.altbeacon.beacon.service.BeaconService">
    </service>
    <service android:enabled="true" android:name="org.altbeacon.beacon.BeaconIntentProcessor">
    </service>
    <receiver android:name="org.altbeacon.beacon.startup.StartupBroadcastReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
            <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
            <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
        </intent-filter>
    </receiver>

关于java - 如何让 AltBeacon 库的 BootstrapRegion 识别 iBeacon 布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25610245/

相关文章:

java - Ehcache 自动生成 key 和@Cacheable spring 注解

java - 从 Spring 查找 activeMQ 目的地

android - 在第二个 ImageView 添加到 RelativeLayout 后,第一个 ImageView 消失

java - Webview.loadData 不适用于低于 3.x 的 Android 设备

android:未检测到信标

java - 如何在 android 中通过缩略图使图像淋浴变大?

java - FrameLayout 和 Bitmap 内存泄漏导致 OOM

android - 加载一张图片时出现内存不足错误

iOS iBeacon/Bluetooth 连接当应用程序死机和消失时

json - 位置管理器和数据管理