Programming my android application with Gimbal sdk doesn't detect the gimbal beacon
Asked Answered
T

1

7

I'm trying to create an android application to detect Gimbal based beacons using the Gimbal sdk but my application cant be able to detect the beacon. But if I try using BluetoothGATT, I can be able to detect the beacon. Following is the part of my code that listens to beacon events. API key verification is successful but still it can't be able to display the proximity.

public class MainActivity extends Activity {

    private PlaceManager placeManager;
    private PlaceEventListener placeEventListener;
    private BeaconEventListener beaconEventListener;
    private BeaconManager beaconManager;
    private String TAG = "beacon";

    public ArrayAdapter<String> listAdapter;
    public ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        Gimbal.setApiKey(getApplication(),
                "MY API KEY ");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        initView();

        monitorPlace();

        listenBeacon();



        CommunicationManager.getInstance().startReceivingCommunications();

    }

    private void listenBeacon() {
        BeaconEventListener beaconEventListener = getBeaconEventListener();
        BeaconManager beaconManager = new BeaconManager();
        beaconManager.addListener(beaconEventListener);
        beaconManager.startListening();
    }

    private void monitorPlace() {
        placeEventListener = getPlaceEventListener();

        // placeManager = PlaceManager.getInstance();
        // placeManager.addListener(placeEventListener);
        placeManager = PlaceManager.getInstance();
        placeManager.addListener(placeEventListener);
        placeManager.startMonitoring();
    }

    private void initView() {
        GimbalLogConfig.enableUncaughtExceptionLogging();
        listAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_expandable_list_item_1);

        listView = (ListView) findViewById(R.id.list);
        listView.setAdapter(listAdapter);
        listAdapter.add(" Gimbal API Key got Set Successfuly");
        listAdapter.notifyDataSetChanged();
        GimbalDebugger.enableBeaconSightingsLogging();
    }

    private BeaconEventListener getBeaconEventListener() {
        Log.i(TAG, "BeaconEventListener started sucessfully...");
        BeaconEventListener beaconSightingListener = new BeaconEventListener() {
            @Override
            public void onBeaconSighting(BeaconSighting beaconSighting) {

                super.onBeaconSighting(beaconSighting);


                listAdapter.add(String.format("Name of  Beacon is %s",
                        beaconSighting.getBeacon().getName()));
                listAdapter.add(String.format("UUID is %s", beaconSighting
                        .getBeacon().getUuid()));
                listAdapter.add(String.format("RSSI is %s",
                        beaconSighting.getRSSI()));
                listAdapter.add(String.format("Battery Level is %s",
                        beaconSighting.getBeacon().getBatteryLevel()));
                listAdapter.add(String.format("Temprature data is %s",
                        beaconSighting.getBeacon().getTemperature()));

            }
        };




    }

    private PlaceEventListener getPlaceEventListener() {

        PlaceEventListener obj = new PlaceEventListener() {
            @Override
            public void onBeaconSighting(BeaconSighting sight, List<Visit> visit) {


                super.onBeaconSighting(sight, visit);

                listAdapter.add(String.format("Beacon Found: %s",
                        sight.getBeacon()));
                listAdapter.add(String.format("Name of Beacon is %s", sight
                        .getBeacon().getName()));
                listAdapter.add(String.format("Identifier  is %s", sight
                        .getBeacon().getIdentifier()));
                listAdapter.add(String.format("RSSI is %s", sight.getRSSI()));
                listAdapter.add(String.format("UUID is %s", sight.getBeacon()
                        .getUuid()));
                listAdapter.add(String.format("Temprature is%s", sight
                        .getBeacon().getTemperature()));
                listAdapter.add(String.format("BatteryLevel is %s", sight
                        .getBeacon().getBatteryLevel()));
                listAdapter.add(String.format("Icon URL is %s", sight
                        .getBeacon().getIconURL()));

                listAdapter.add(String.format("Start Visit for %s", visit
                        .iterator().toString()));

            }

            // @Override
            public void onVisitStart(Visit visit) {
                 super.onVisitStart(visit);

                listAdapter.add(String.format("Start Visit for %s", visit
                        .getPlace().getName()));

                Toast.makeText(getApplicationContext(),
                        visit.getPlace().getName(), Toast.LENGTH_SHORT).show();
                listAdapter.notifyDataSetChanged();

            }

            @Override
            public void onVisitEnd(Visit visit) {
                // TODO Auto-generated method stub
                super.onVisitEnd(visit);

                listAdapter.add(String.format("End Visit for %s", visit
                        .getPlace().getName()));
                listAdapter.notifyDataSetChanged();

            }

        };


        return obj;
    }

}
Threadbare answered 7/9, 2015 at 15:10 Comment(6)
The sample code does not show how are you using the BeaconEventListener instance. Did you add it to the BeaconManager and started listening?Glimp
Yes I created an instance for BeaconEventListener and by using BeaconManager , I started listening.Threadbare
Could you add that code to the question as well? The creation of the listener does not give much details on what could have gone wrong.Glimp
For one, I see that you're not calling listAdapter.notifyDataSetChanged(); in the onBeaconSighting() method. Could it be that it is just not displaying the beacons, but they're detected? Did you define places in GimbalManager? My suggestion is to strip off all the code that is not directly used for plain beacon detection (so leave only BeaconEventListener, and remove PlaceEventListener and CommunicationsManager) and see how it goes. Did you check if you have added all needed permissions and features in AndroidManifest? Did you have a look at the Gimbal sample app, how it's done there?Glimp
Yes I looked at the sample app. I'm successful in getting BeaconEvents and PlaceEvents. Now I'm facing troubles in sending push notifications. Where in my code should I invoke registerForPush method?Threadbare
It could be done in an activity, as far as I know, but maybe it would be good to create another topic and describe the problem you're facing. Maybe you could write an answer yourself for this question, so that others facing the similar problem would find it helpful?Glimp
D
4

Adding the beacon details in Gimbal manager did solve the problem. Got the below line from Gimbal team

It is mandatory to add the beacons in Gimbal Manager for detecting beacons

Disposure answered 16/9, 2015 at 13:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.