0
votes

Using the code from https://altbeacon.github.io/android-beacon-library/samples.html trying to detect a IBeacon emitter that is ios 8 as follow http://blog.passkit.com/configure-iphone-ibeacon-transmitter/ and am a bit loss in what step is wrong, do i need to use BeaconIdentifier in Region as myMonitoringUniqueId? can't detect the IBeacon.... do I need a extra step to listen to IBeacon from ios since the lib using is Android Beacon Library

also added

beaconManager.getBeaconParsers().add(new BeaconParser(). setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));

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

BeaconIdentifier = @"com.example.apple-samplecode.AirLocate";

import android.app.Activity;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import android.widget.TextView;

import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.MonitorNotifier;
import org.altbeacon.beacon.Region;
import org.altbeacon.beacon.logging.LogManager;


public class MainActivity extends Activity implements BeaconConsumer{

    protected static final String TAG = "MonitoringActivity";
    private BeaconManager beaconManager;
    private TextView message;
    private TextView num;
    private int IBeaconCount;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        message = (TextView)findViewById(R.id.IBeaconMsg);
        num = (TextView)findViewById(R.id.Numdetect);
        beaconManager = BeaconManager.getInstanceForApplication(this);
        /*
        *  beaconManager.getBeaconParsers().add(new BeaconParser().
               setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
        * */
        beaconManager.getBeaconParsers().add(new BeaconParser().
                setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
        //
        beaconManager.bind(this);
        //Hz to see if its receiveing from the emitter
        //beaconManager.setForegroundScanPeriod(2000l);
        //beaconManager.setBackgroundBetweenScanPeriod(1100l);
        //

        //IBeaconCount = 0;
        //num.setText(IBeaconCount);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        beaconManager.unbind(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        //num.setText(IBeaconCount);
    }

    @Override
    public void onBeaconServiceConnect() {
        beaconManager.setMonitorNotifier(new MonitorNotifier() {
            @Override
            public void didEnterRegion(Region region) {
                //IBeaconCount++;
                Log.i(TAG, "I just saw an beacon for the first time!");
                message.setText("I just saw an beacon for the first time!");
                LogManager.d(TAG, "didEnterRegion %s", region);

            }

            @Override
            public void didExitRegion(Region region) {
                Log.i(TAG, "I no longer see an beacon");
                message.setText("I no longer see an beacon");
            }

            @Override
            public void didDetermineStateForRegion(int state, Region region) {
                Log.i(TAG, "I have just switched from seeing/not seeing beacons: "+state);
                message.setText("I have just switched from seeing/not seeing beacons: "+state);
            }
        });

        try {
            //beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
            beaconManager.startMonitoringBeaconsInRegion(new Region("com.example.apple-samplecode.AirLocate", null, null, null));
        } catch (RemoteException e) {    }
    }

}

still not showing the Log message of didEnterRegion Edited file Log:

04-08 12:45:39.283    7223-7223/com.mobinteg.ibeacon W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device.  Using default
04-08 12:45:39.283    7223-7223/com.mobinteg.ibeacon W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device.  Using default
04-08 12:45:39.303    7223-7223/com.mobinteg.ibeacon I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build:  ()
    OpenGL ES Shader Compiler Version: E031.24.00.08
    Build Date: 03/21/14 Fri
    Local Branch: AU200+patches_03212014
    Remote Branch:
    Local Patches:
    Reconstruct Branch:
04-08 12:45:39.343    7223-7223/com.mobinteg.ibeacon D/OpenGLRenderer﹕ Enabling debug mode 0
04-08 12:45:39.413    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ startLeScan(): null
04-08 12:45:39.453    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-08 12:45:39.483    7223-7262/com.mobinteg.ibeacon I/System.out﹕ Thread-1162(HTTPLog):isShipBuild true
04-08 12:45:39.483    7223-7262/com.mobinteg.ibeacon I/System.out﹕ Thread-1162(HTTPLog):SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
04-08 12:45:39.523    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=64:98:8D:4F:33:00 RSSI=-45
04-08 12:45:39.573    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=6A:7F:9C:42:A0:00 RSSI=-80
04-08 12:45:40.123    7223-7262/com.mobinteg.ibeacon W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device.  Using default
04-08 12:45:40.563    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ stopLeScan()
04-08 12:45:40.563    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ startLeScan(): null
04-08 12:45:40.563    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-08 12:45:40.603    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=64:98:8D:4F:33:00 RSSI=-45
04-08 12:45:40.673    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=6A:7F:9C:42:A0:00 RSSI=-80
04-08 12:45:41.673    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ stopLeScan()
04-08 12:45:41.673    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ startLeScan(): null
04-08 12:45:41.673    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-08 12:45:41.713    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=64:98:8D:4F:33:00 RSSI=-44
04-08 12:45:42.783    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ stopLeScan()
04-08 12:45:42.803    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ startLeScan(): null
04-08 12:45:42.813    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-08 12:45:42.883    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=64:98:8D:4F:33:00 RSSI=-44
04-08 12:45:43.053    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=6A:7F:9C:42:A0:00 RSSI=-87
04-08 12:45:43.933    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ stopLeScan()
04-08 12:45:43.943    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ startLeScan(): null
04-08 12:45:43.953    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-08 12:45:44.003    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=6A:7F:9C:42:A0:00 RSSI=-79
04-08 12:45:44.013    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=64:98:8D:4F:33:00 RSSI=-39
04-08 12:45:45.063    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ stopLeScan()

----------------------------------------------Edit 2----------------------------------------------------------

added the RangeNotifier as below inside the onBeaconServiceConnect but it never enters didRangeBeaconsInRegion and didEnterRegion,didExitRegion and didDetermineStateForRegion only fires once when the app starts how to make it alls listinig only stop when the app is closed can someone point how to do that?

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

            /*
            for(Beacon beacon: beacons){
                Log.i(TAG, "Beacon detected with id1: "+beacon.getId1()+" id2:"+beacon.getId2()+" id3: "+beacon.getId3()+" distance: "+beacon.getDistance());
            }
            */
        }


    });

Log file:

04-09 12:28:16.383  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Waiting to stop scan cycle for another 1100 milliseconds
04-09 12:28:16.383  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Scan started
04-09 12:28:16.383  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Set scan periods called with 1100, 110 Background mode must have changed.
04-09 12:28:16.383  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ We are not in the background.  Cancelling wakeup alarm
04-09 12:28:16.383  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ cancel wakeup alarm: null
04-09 12:28:16.433  27850-27874/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=73:A5:A7:D6:24:06 RSSI=-67
04-09 12:28:16.433  27850-27874/com.mobinteg.ibeacon D/CycledLeScannerForJellyBeanMr2﹕ got record
04-09 12:28:16.443  27850-27872/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=D0:4F:7E:0A:88:5B RSSI=-92
04-09 12:28:16.443  27850-27872/com.mobinteg.ibeacon D/CycledLeScannerForJellyBeanMr2﹕ got record
04-09 12:28:16.443  27850-27891/com.mobinteg.ibeacon D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting be ac.  The bytes I see are: 02011a0bff4c0009060102000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
04-09 12:28:16.443  27850-27891/com.mobinteg.ibeacon D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting 02 15.  The bytes I see are: 02011a0bff4c0009060102000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
04-09 12:28:16.443  27850-27890/com.mobinteg.ibeacon D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting be ac.  The bytes I see are: 02011a1aff4c00021513ba60dbdcdb42ec99a33f7eef7bbdbd00000000c50000000000000000000000000000000000000000000000000000000000000000
04-09 12:28:16.443  27850-27890/com.mobinteg.ibeacon D/BeaconParser﹕ This is a recognized beacon advertisement -- 02 15 seen
04-09 12:28:16.443  27850-27890/com.mobinteg.ibeacon D/BeaconService﹕ beacon detected : id1: 13ba60db-dcdb-42ec-99a3-3f7eef7bbdbd id2: 0 id3: 0
04-09 12:28:16.443  27850-27890/com.mobinteg.ibeacon D/Callback﹕ attempting callback via intent: ComponentInfo{com.mobinteg.ibeacon/org.altbeacon.beacon.BeaconIntentProcessor}
04-09 12:28:16.453  27850-27890/com.mobinteg.ibeacon D/BeaconService﹕ looking for ranging region matches for this beacon
04-09 12:28:16.453  27850-27892/com.mobinteg.ibeacon D/BeaconIntentProcessor﹕ got an intent to process
04-09 12:28:16.453  27850-27892/com.mobinteg.ibeacon D/BeaconIntentProcessor﹕ got monitoring data
04-09 12:28:16.453  27850-27892/com.mobinteg.ibeacon D/BeaconIntentProcessor﹕ Calling monitoring notifier: com.mobinteg.ibeacon.MainActivity$2@420d5b28
04-09 12:28:16.453  27850-27892/com.mobinteg.ibeacon I/MonitoringActivity﹕ I have just switched from seeing/not seeing beacons: 1
04-09 12:28:16.453  27850-27892/com.mobinteg.ibeacon I/MonitoringActivity﹕ I just saw an beacon for the first time!
04-09 12:28:17.383  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Waiting to stop scan cycle for another 97 milliseconds
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Done with scan cycle
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ stopping bluetooth le scan
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/BluetoothAdapter﹕ stopLeScan()
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Normalizing between scan period from 110 to -1027
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ starting a new scan cycle
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ starting a new bluetooth le scan
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/BluetoothAdapter﹕ startLeScan(): null
04-09 12:28:17.493  27850-27872/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Waiting to stop scan cycle for another 1100 milliseconds
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Scan started
04-09 12:28:17.503  27850-27874/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=73:A5:A7:D6:24:06 RSSI=-63
04-09 12:28:17.503  27850-27874/com.mobinteg.ibeacon D/CycledLeScannerForJellyBeanMr2﹕ got record
04-09 12:28:17.503  27850-28015/com.mobinteg.ibeacon D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting be ac.  The bytes I see are: 02011a1aff4c00021513ba60dbdcdb42ec99a33f7eef7bbdbd00000000c50000000000000000000000000000000000000000000000000000000000000000
04-09 12:28:17.503  27850-28015/com.mobinteg.ibeacon D/BeaconParser﹕ This is a recognized beacon advertisement -- 02 15 seen
04-09 12:28:17.503  27850-28015/com.mobinteg.ibeacon D/BeaconService﹕ beacon detected multiple times in scan cycle : id1: 13ba60db-dcdb-42ec-99a3-3f7eef7bbdbd id2: 0 id3: 0
04-09 12:28:17.503  27850-28015/com.mobinteg.ibeacon D/BeaconService﹕ beacon detected : id1: 13ba60db-dcdb-42ec-99a3-3f7eef7bbdbd id2: 0 id3: 0
04-09 12:28:17.503  27850-28015/com.mobinteg.ibeacon D/BeaconService﹕ looking for ranging region matches for this beacon
04-09 12:28:18.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Waiting to stop scan cycle for another 99 milliseconds

---------------------------------------edit 3-------------------------------------

changed the Log inside didEnterRegion to

Log.i(TAG, "I just saw an beacon for the first time! Id1->"+region.getId1());

and started to enter didRangeBeaconsInRegion but beacons.size() appears as 0......

---------------------------------------edit 4--------------------------------------

ok with Log.i(TAG, "I just saw an beacon for the first time! Id1->"+region.getId1()+" id 2:"+region.getId2()+" id 3:"+region.getId3()); the device appears and the distance is working fine now...

1
Make sure your beacon is transmitting and it works with an off the shelf app like Locate. play.google.com/store/apps/…davidgyoung
actualy its showing D/BluetoothAdapter﹕ onScanResult() - Device=64:98:8D:4F:33:00 RSSI=-48 but no message from MonitorNotifier, with the Visible Beacons it detects the beaconH.C
nvm needed beaconManager.getBeaconParsers() that was in comment... wokring knowH.C

1 Answers

0
votes

It is important you start Advertizing. call this which worked for me.

public void startEmitting() {
        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);
    }