I'm working on a simple beacon proximity app using AltBeacon library from here https://altbeacon.github.io/android-beacon-library/samples.html
I am experimenting with the sample code provided on the above website, however, each time I run the app it only goes to didDetermineStateForRegion() method. If it detected the beacon it would go to didEnterRegion() method.
I'm not sure what I'm doing wrong and was unable to find the answer in other questions.
There is the same issue with the reference app provided on the mentioned website but Locate app (based on AltBeacon) instantly detects my beacon.
My beacon is set to 152ms transmission interval and maximum transmission power.
This is my code:
MainActivity
public class MainActivity extends AppCompatActivity implements BeaconConsumer {
protected final String TAG = "Beacons Monitoring";
private BeaconManager beaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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.bind(this);
}
public void onDestroy(){
super.onDestroy();
beaconManager.unbind(this);
}
@Override
public void onBeaconServiceConnect() {
beaconManager.addMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
Log.e(TAG,"I just saw a beacon for the first time");
}
@Override
public void didExitRegion(Region region) {
Log.e(TAG, "I lost my beacons :( ");
}
@Override
public void didDetermineStateForRegion(int i, Region region) {
Log.e(TAG, "I just switched from seeing/not seeing a beacon. STATE: " + i);
}
});
try {
beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
} catch (RemoteException e){
Log.e(TAG, "EXCEPTION!!! :'( ");
}
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.michal.beacons2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Does anyone know what could be wrong in my code?