Hello, I’m new to estimote sdk, using android studio. I got one beacon at home, and I want to work on it, get some flow with the sdk.
Using Xiaomi with android 4.4.4 api19
I got weird problem, my phone discovers nearable but the actual list of nearables is empty. Googled on it some time and no one had similar problem. It might be something really simple that i can’t figure out just now. You got any idea? Got bluetooth enabled, only one beacon is close to me, on hackathon bluetooth crushed due to overload of beacons.
My code
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.estimote.sdk.Beacon;
import com.estimote.sdk.BeaconManager;
import com.estimote.sdk.Nearable;
import com.estimote.sdk.Region;
import java.util.List;
public class MainActivity extends ActionBarActivity {
private BeaconManager beaconManager;
private String scanId;
private Nearable currentNearable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
beaconManager = new BeaconManager(getApplicationContext());
setContentView(R.layout.activity_main);
beaconManager.setNearableListener(new BeaconManager.NearableListener() {
@Override
public void onNearablesDiscovered(List<Nearable> list) {
Log.d(null, "nearable discovered");
Log.e(null, String.valueOf(list.size()));
int maxPower = 0;
if (!list.isEmpty()) {
Log.e(null, "in");
maxPower = list.get(0).power.powerInDbm;
currentNearable = list.get(0);
for (Nearable nearable : list) {
if (maxPower < nearable.power.powerInDbm) {
maxPower = nearable.power.powerInDbm;
currentNearable = nearable;
}
}
displayCurrentNearableInfo();
}
}
});
}
@Override
protected void onStart() {
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
public void onServiceReady() {
scanId = beaconManager.startNearableDiscovery();
}
});
super.onStart();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onDestroy() {
beaconManager.disconnect();
super.onDestroy();
}
@Override protected void onStop() {
beaconManager.stopNearableDiscovery(scanId);
super.onStop();
}
private void displayCurrentNearableInfo() {
if(currentNearable != null){
StringBuilder builder = new StringBuilder()
.append("temperature: ").append(currentNearable.temperature).append("\n")
.append("contents: ").append(currentNearable.describeContents())
.append("power: " ).append(currentNearable.power.powerInDbm);
TextView infoText = (TextView) findViewById(R.id.textView);
infoText.setText(builder.toString());
}
}
}
Console
11-10 23:08:29.460 22246-22259/com.example.tom.test D/BluetoothAdapter﹕ startLeScan(): null
11-10 23:08:29.480 22246-24134/com.example.tom.test D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
11-10 23:08:30.510 22246-22259/com.example.tom.test D/BluetoothAdapter﹕ stopLeScan()
11-10 23:08:30.520 22246-22246/com.example.tom.test D/﹕ nearable discovered
11-10 23:08:30.520 22246-22246/com.example.tom.test E/﹕ 0