我用的是参考,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库在后台检测iBeacons。我从我的项目中包含了以下代码片段。到目前为止,我还没有在后台检测到ibeacons……任何帮助都是值得感谢的。
我用beaconmanager

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

但是,我没有得到错误和信标检测。在三星galaxy 4设备上运行app-in-debug时,app会启动,但不会检测到活动的信标。我的信标是rad信标,配置为ibeacons。rad beacon应用程序会检测到它们,我在前台运行的另一个altbeacon库应用程序也会检测到我的ibeacons。这些应用程序运行在三星Galaxy 4上。
我为后台信标检测设置的应用程序…不检测iBeacons。
这是我的密码。JavaSt.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) {   }
}
}
*/
}

我没有发现任何伊贝肯病毒。没有发布预期的logcat列表。我是不是漏了一步?

最佳答案

编辑project.properties文件并添加行:

manifestmerger.enabled=true

请参阅此处的完整说明:
http://altbeacon.github.io/android-beacon-library/configure.html
这个问题与你试图识别的信标类型无关。如果没有启用清单合并,androidmanifest.xml文件没有从库继承的服务定义来启动Beaconservice,因此永远不会检测到任何类型的信标。
使用eclipse,您可以通过执行构建来判断清单合并是否正常工作,然后在bin/androidmanifest.xml中查看生成的清单。此清单应包括以下条目。
如果所有其他操作都失败,则可以手动将这些条目复制到项目清单中:
<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/

10-11 14:23