Hi I am using the sample code from here but getting errors while building the app. I have downloaded the latest iBeacon library android-beacon-library-2.7.tar.gz
and added to project as explained in the website.
Here is the MainActivity.class
package com.example.ibeacontest;
import android.util.Log;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.MonitorNotifier;
import org.altbeacon.beacon.startup.BootstrapNotifier;
import android.app.Activity;
import android.graphics.Region;
import android.os.Bundle;
import android.os.RemoteException;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity implements BeaconConsumer {
protected static final String TAG = "MonitoringActivity";
private BeaconManager beaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beaconManager = BeaconManager.getInstanceForApplication(this);
// To detect proprietary beacons, you must add a line like below corresponding to your beacon
// type. Do a web search for "setBeaconLayout" to get the proper expression.
// beaconManager.getBeaconParsers().add(new BeaconParser().
// setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
beaconManager.bind(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
beaconManager.unbind(this);
}
public void onBeaconServiceConnect() {
beaconManager.setMonitorNotifier(new MonitorNotifier() {
public void didEnterRegion(Region region) {
Log.i(TAG, "I just saw an beacon for the first time!");
}
public void didExitRegion(Region region) {
Log.i(TAG, "I no longer see an beacon");
}
public void didDetermineStateForRegion(int state, Region region) {
Log.i(TAG, "I have just switched from seeing/not seeing beacons: "+state);
}
});
try {
beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
} catch (RemoteException e) { }
}
}
Error:
Description Resource Path Location Type
The constructor Region(String, null, null, null) is undefined MainActivity.java /iBeaconTest/src/com/example/ibeacontest line 56 Java Problem
The method startMonitoringBeaconsInRegion(org.altbeacon.beacon.Region) in the type BeaconManager is not applicable for the arguments (android.graphics.Region) MainActivity.java /iBeaconTest/src/com/example/ibeacontest line 56 Java Problem
The type new MonitorNotifier(){} must implement the inherited abstract method MonitorNotifier.didDetermineStateForRegion(int, Region) MainActivity.java /iBeaconTest/src/com/example/ibeacontest line 40 Java Problem
The type new MonitorNotifier(){} must implement the inherited abstract method MonitorNotifier.didEnterRegion(Region) MainActivity.java /iBeaconTest/src/com/example/ibeacontest line 40 Java Problem
The type new MonitorNotifier(){} must implement the inherited abstract method MonitorNotifier.didExitRegion(Region) MainActivity.java /iBeaconTest/src/com/example/ibeacontest line 40 Java Problem
What could be the issue?
One of the import
statements is referring to the wrong package. Simply change:
import android.graphics.Region;
to import org.altbeacon.beacon.Region;
Before I made that change I got the same errors as shown in the question. Afterward, the code compiled successfully.