Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

My app can't find beacons #26

Open
5 tasks done
omicito opened this issue May 22, 2019 · 2 comments
Open
5 tasks done

My app can't find beacons #26

omicito opened this issue May 22, 2019 · 2 comments

Comments

@omicito
Copy link

omicito commented May 22, 2019

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • My beacons have Estimote Location packet enabled (Check it in the Estimote Cloud, or via app)
    • My Android device/devices supports BLE and has Android OS version >= 5.0.0
    • My Android device/devices have bluetooth enabled
    • My app has Location Permissions granted

Basic information

Estimote SDK version: 2.5.3

Android devices affected: Xiaomi Redmi Note 4

Beacon hardware version: D3.4

Description

I am building an Android app for an indoor location using Android Indoor SDK.
The issue is that my phone can't find any beacons near and it is not showing my location.
The Estimode app finds beacons, but my app is not scanning them.
When I debugged, I saw that the "location" object has scannedBeacon member and its value is 0.
The location is mapped and successfully shown on my app, along with the beacon's position.
The Bluetooth is on and scanning, I can see this in the log:
D/BluetoothAdapter: STATE_ON
D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=10 mClientIf=0

In the setOnPositionUpdateListener, it always goes on onPositionOutsideLocation(), he can't find any beacons and he thinks he is outside of the room.

Please, can you help me?

package com.example.indoor;

import android.annotation.TargetApi;

import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import android.widget.Button;
import android.widget.Toast;


import com.estimote.indoorsdk.EstimoteCloudCredentials;
import com.estimote.indoorsdk.IndoorLocationManagerBuilder;
import com.estimote.indoorsdk_module.algorithm.OnPositionUpdateListener;
import com.estimote.indoorsdk_module.cloud.CloudCredentials;
import com.estimote.indoorsdk_module.cloud.Location;
import com.estimote.indoorsdk_module.view.IndoorLocationView;

import com.estimote.indoorsdk_module.cloud.CloudCallback;
import com.estimote.indoorsdk_module.cloud.EstimoteCloudException;
import com.estimote.indoorsdk_module.cloud.IndoorCloudManager;
import com.estimote.indoorsdk_module.cloud.IndoorCloudManagerFactory;

import com.estimote.indoorsdk_module.algorithm.ScanningIndoorLocationManager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.estimote.indoorsdk_module.cloud.LocationPosition;


import android.os.*;
import android.Manifest;

public class MainActivity extends AppCompatActivity {
    IndoorLocationView indoorLocationView;
    ScanningIndoorLocationManager indoorLocationManager;
    Location loc;
    IndoorCloudManager cloudManager;
    CloudCredentials cloudCredentials;
    final private int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 124;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        cloudCredentials = new EstimoteCloudCredentials("my-app", "token"); //i removed real values
        cloudManager = new IndoorCloudManagerFactory().create(this, cloudCredentials);


        if (Build.VERSION.SDK_INT >= 23) {
            // Marshmallow+ Permission APIs
            permissions();
        }
        Handler handler2 = new Handler();
        Handler handler3 = new Handler();
        Handler handler4 = new Handler();

        getLocation();

        handler2.postDelayed(new Runnable() {
            public void run() {
                locationBuilder();
            }
        }, 2000);
        handler3.postDelayed(new Runnable() {
            public void run() {
                positionListener();
            }
        }, 2000);
        handler4.postDelayed(new Runnable() {
            public void run() {
                startPositioning();
            }
        }, 2000);

  

    }

    @Override
    protected void onStop () {
        super.onStop();
        indoorLocationManager.stopPositioning();
    }

    private void getLocation()
    {
        cloudManager.getLocation("my-loc", new CloudCallback<Location>() {
            @Override
            public void success(Location location) {
                // do something with your Location object here.
                // You will need it to initialise IndoorLocationManager!
                indoorLocationView = findViewById(R.id.indoor);
                indoorLocationView.setLocation(location);
                loc = location;
            }

            @Override
            public void failure(EstimoteCloudException e) {
                // oops!
                Toast.makeText(MainActivity.this, "Error", Toast.LENGTH_LONG).show();
            }
        });
    }

    private void locationBuilder()
    {
        cloudCredentials = new EstimoteCloudCredentials("xxx", "yyy"); //I removed real values
        indoorLocationManager =
                new IndoorLocationManagerBuilder(MainActivity.this, loc, cloudCredentials)
                        .withDefaultScanner()
                        .build();
    }

    private void positionListener()
    {
        indoorLocationManager.setOnPositionUpdateListener(new OnPositionUpdateListener() {

            @Override
            public void onPositionUpdate(LocationPosition locationPosition) {
                indoorLocationView.updatePosition(locationPosition);
                Log.d("Tag", "I'm in");
                // Toast.makeText(MainActivity.this, "Location", Toast.LENGTH_SHORT)
                //       .show();
            }

            @Override
            public void onPositionOutsideLocation() {

                indoorLocationView.hidePosition();
                //   Log.d("TAG", "I'm out");
            }
        });
    }

    private void startPositioning()
    {
        indoorLocationManager.startPositioning();
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS: {
                Map<String, Integer> perms = new HashMap<String, Integer>();
                // Initial
                perms.put(Manifest.permission.ACCESS_FINE_LOCATION, PackageManager.PERMISSION_GRANTED);


                // Fill with results
                for (int i = 0; i < permissions.length; i++)
                    perms.put(permissions[i], grantResults[i]);

                // Check for ACCESS_FINE_LOCATION
                if (perms.get(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED

                ) {
                    // All Permissions Granted

                    // Permission Denied
                    Toast.makeText(MainActivity.this, "All Permission GRANTED !! Thank You :)", Toast.LENGTH_SHORT)
                            .show();


                } else {
                    // Permission Denied
                    Toast.makeText(MainActivity.this, "One or More Permissions are DENIED Exiting App :(", Toast.LENGTH_SHORT)
                            .show();

                    finish();
                }
            }
            break;
            default:
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }


    @TargetApi(Build.VERSION_CODES.M)
    private void permissions() {
        List<String> permissionsNeeded = new ArrayList<String>();

        final List<String> permissionsList = new ArrayList<String>();
        if (!addPermission(permissionsList, Manifest.permission.ACCESS_FINE_LOCATION))
            permissionsNeeded.add("Show Location");

        if (permissionsList.size() > 0) {
            if (permissionsNeeded.size() > 0) {

                // Need Rationale
                String message = "App need access to " + permissionsNeeded.get(0);

                for (int i = 1; i < permissionsNeeded.size(); i++)
                    message = message + ", " + permissionsNeeded.get(i);

                showMessageOKCancel(message,
                        new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),
                                        REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
                            }
                        });
                return;
            }
            requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),
                    REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
            return;
        }

        Toast.makeText(MainActivity.this, "No new Permission Required- Launching App .You are Awesome!!", Toast.LENGTH_SHORT)
                .show();
    }

    private void showMessageOKCancel(String message, DialogInterface.OnClickListener okListener) {
        new AlertDialog.Builder(MainActivity.this)
                .setMessage(message)
                .setPositiveButton("OK", okListener)
                .setNegativeButton("Cancel", null)
                .create()
                .show();
    }

    @TargetApi(Build.VERSION_CODES.M)
    private boolean addPermission(List<String> permissionsList, String permission) {

        if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
            permissionsList.add(permission);
            // Check for Rationale Option
            if (!shouldShowRequestPermissionRationale(permission))
                return false;
        }
        return true;
    }

}
@ahmedessam100
Copy link

Hello,

Do you solve this problem?

@omicito
Copy link
Author

omicito commented Oct 22, 2019 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants