Estimote / Android-Indoor-SDK

Estimote Indoor SDK for Android
MIT License
63 stars 28 forks source link

My app can't find beacons #26

Open omicito opened 5 years ago

omicito commented 5 years ago

Prerequisites

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 commented 5 years ago

Hello,

Do you solve this problem?

omicito commented 5 years ago

Hello,

I did not solve it... I stopped working on that project

uto, 22. lis 2019. 12:51 Ahmed Essam Mohamed notifications@github.com je napisao:

Hello,

Do you solve this problem?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Estimote/Android-Indoor-SDK/issues/26?email_source=notifications&email_token=AL7RVK3TAXUM2D6IQ2REC5DQP3LKTA5CNFSM4HORINNKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEB5JTOY#issuecomment-544905659, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL7RVK3PER4DGATCULVNYLLQP3LKTANCNFSM4HORINNA .