hello guys , i need your help . I followed tutorial at https://github.com/Estimote/Android-Indoor-SDK to make indoor location application . i copy the code and make the apk without error , however when i tried to run the application , it’s forced close
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.estimote.coresdk.cloud.api.CloudCallback;
import com.estimote.coresdk.common.config.EstimoteSDK;
import com.estimote.coresdk.common.exception.EstimoteCloudException;
import com.estimote.indoorsdk.algorithm.IndoorLocationManagerBuilder;
import com.estimote.indoorsdk.algorithm.OnPositionUpdateListener;
import com.estimote.indoorsdk.algorithm.ScanningIndoorLocationManager;
import com.estimote.indoorsdk.cloud.IndoorCloudManager;
import com.estimote.indoorsdk.cloud.IndoorCloudManagerFactory;
import com.estimote.indoorsdk.cloud.Location;
import com.estimote.indoorsdk.cloud.LocationPosition;
import com.estimote.indoorsdk.view.IndoorLocationView;
public class MainActivity extends AppCompatActivity {
IndoorLocationView indoorLocationView = (IndoorLocationView) findViewById(R.id.indoor_view);
Location location;
Context applicatonContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// To get your AppId and AppToken you need to create a new application in Estimote Cloud.
EstimoteSDK.initialize(applicatonContext, "indoorapp-935", "eeba015c996a025b873fad2969ff7a6c");
// Optional, debug logging.
EstimoteSDK.enableDebugLogging(true);
IndoorCloudManager cloudManager = new IndoorCloudManagerFactory().create(this);
indoorLocationView.setLocation(location);
cloudManager.getLocation("your-location-id-here", new CloudCallback<Location>() {
@Override
public void success(Location location) {
// do something with your Location object here.
// You will need it to initialise IndoorLocationManager!
indoorLocationView = (IndoorLocationView) findViewById(R.id.indoor_view);
indoorLocationView.setLocation(location);
}
@Override
public void failure(EstimoteCloudException e) {
// oops!
}
});
indoorLocationManager.setOnPositionUpdateListener(new OnPositionUpdateListener() {
@Override
public void onPositionUpdate(LocationPosition locationPosition) {
indoorLocationView.updatePosition(locationPosition);
}
@Override
public void onPositionOutsideLocation() {
indoorLocationView.hidePosition();
}
});
}
ScanningIndoorLocationManager indoorLocationManager =
new IndoorLocationManagerBuilder(this, location)
.withDefaultScanner()
.build();
@Override
protected void onStart() {
super.onStart();
indoorLocationManager.startPositioning();
}
@Override
protected void onStop() {
super.onStop();
indoorLocationManager.stopPositioning();
}
}
I suspect the problem is my App that i create in estimode cloud cause the problem ( i chose “My Own App”) , what do you think guys ? please tell me
Hi,
There is several problems in your code, and non of them is related to App type you created on Estimote cloud
-
indoorLocationView instance (just like all view instances in Android) cannot be initialised before activity receives it content layout. Before setContentView(R.layout.activity_main);
call in onCreate
Activity simply do not have any layout defined, thus no views yet. In other words - all findViewById(...)
calls have to be done AFTER setContentView(...)
call.
-
When You calling api with callback method passed as an argument (like cloudManager.getLocation(...)
), you HAVE TO keep in mind that callback is called asynchronously. In other words - method accepting callback is not blocking, it ends immediately and the callback is called in some other point of time - generally LATER, So, when some values are initialised inside of callback, you have to keep in mind that those values are not initialised from the very beginning. They will be initialised when callback gets called by the api - this mean asynchronously, LATER
-
There are some minor pitfalls like applicatonContext
variable which is never initialised…
I briefly updated the code snipet you provided, here it goes:
package com.estimote.wafel.sandbox;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.estimote.coresdk.cloud.api.CloudCallback;
import com.estimote.coresdk.common.config.EstimoteSDK;
import com.estimote.coresdk.common.exception.EstimoteCloudException;
import com.estimote.indoorsdk.algorithm.IndoorLocationManagerBuilder;
import com.estimote.indoorsdk.algorithm.OnPositionUpdateListener;
import com.estimote.indoorsdk.algorithm.ScanningIndoorLocationManager;
import com.estimote.indoorsdk.cloud.IndoorCloudManager;
import com.estimote.indoorsdk.cloud.IndoorCloudManagerFactory;
import com.estimote.indoorsdk.cloud.Location;
import com.estimote.indoorsdk.cloud.LocationPosition;
import com.estimote.indoorsdk.view.IndoorLocationView;
public class MainActivity extends AppCompatActivity {
IndoorLocationView indoorLocationView;
ScanningIndoorLocationManager indoorLocationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
indoorLocationView = (IndoorLocationView) findViewById(R.id.indoor_view);
// To get your AppId and AppToken you need to create a new application in Estimote Cloud.
EstimoteSDK.initialize(getApplicationContext(), "indoorapp-935", "eeba015c996a025b873fad2969ff7a6c");
// Optional, debug logging.
EstimoteSDK.enableDebugLogging(true);
IndoorCloudManager cloudManager = new IndoorCloudManagerFactory().create(this);
// indoorLocationView.setLocation(location);
cloudManager.getLocation("your-location-id-here", new CloudCallback<Location>() {
@Override
public void success(Location location) {
// do something with your Location object here.
// You will need it to initialise IndoorLocationManager!
indoorLocationManager = new IndoorLocationManagerBuilder(MainActivity.this, location)
.withDefaultScanner()
.build();
indoorLocationManager.setOnPositionUpdateListener(new OnPositionUpdateListener() {
@Override
public void onPositionUpdate(LocationPosition locationPosition) {
indoorLocationView.updatePosition(locationPosition);
}
@Override
public void onPositionOutsideLocation() {
indoorLocationView.hidePosition();
}
});
indoorLocationManager.startPositioning();
indoorLocationView = (IndoorLocationView) findViewById(R.id.indoor_view);
indoorLocationView.setLocation(location);
}
@Override
public void failure(EstimoteCloudException e) {
// oops!
}
});
}
@Override
protected void onStart() {
super.onStart();
}
@Override
protected void onStop() {
super.onStop();
if (indoorLocationManager != null)
indoorLocationManager.stopPositioning();
}
}
Regards
Wojtek
Thanks for your reply mr wotjek , also thank for your help fixing my code to i still new to android programming so i don’t really understand OOP . your coding work well , however the result is blank screen in my phone , is it because the template type that i use isn’t correct ? i selected estimode cloud app , “my own app” ( in this website http://developer.estimote.com/indoor/build-an-app/ said that i must chose “Web App” to get App id and App token ) because i didn’t find “web App” selection . Would you help me again mr. Wotjek ?
@Wojciech_Wawerek
Hi,
I don’t think the application template type you used on cloud causes the issue you struggling with.
Have you any location configured on cloud?
Are you providing id of the location you are interested with when calling cloudManager.getLocation(...)
?
Check out our example app, It might address a loot of questions/concerns you might have: https://github.com/Estimote/Android-Indoor-SDK
Regards
Wojtek