Some versions of Android do not find beacon or are significantly slow to find

87 Views Asked by At

im not good at english, so i hope you understand me plz. i want to use beacon in android and i used estimote sdk and ibeacon Galaxy S4(andorid 5.0.1) worked well but other phone do not find beacons or are significantly slow to find. plz tell me what

MainActivity.java

package com.example.estimotetest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.estimote.sdk.Beacon;
import com.estimote.sdk.BeaconManager;
import com.estimote.sdk.Region;
import com.estimote.sdk.SystemRequirementsChecker;
import java.util.List;
import java.util.UUID;

public class MainActivity extends AppCompatActivity {
    private BeaconManager beaconManager;
   private TextView tvId;
   private boolean isConnected;
   private Region region;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       tvId = (TextView) findViewById(R.id.tvId);
       beaconManager = new BeaconManager(this);
       isConnected = false;

       // add this below:
       beaconManager.setRangingListener(new BeaconManager.RangingListener() {
            @Override
           public void onBeaconsDiscovered(Region region, List list) {
                if (!list.isEmpty()) {
                    Beacon nearestBeacon = (Beacon) list.get(0);
                   Log.d("Airport", "Nearest places: " + nearestBeacon.getRssi());

                   tvId.setText(nearestBeacon.getRssi() + "");
               }
            }
        });

       region = new Region("ranged region",
               UUID.fromString("b9407f30-f5f8-466e-aff9-25556b57fe6d"), null, null); 
   }

    @Override
   protected void onResume() {
        super.onResume();

       SystemRequirementsChecker.checkWithDefaultDialogs(this);

       beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
            @Override
           public void onServiceReady() {
                beaconManager.startRanging(region);
           }
        });
   }
    @Override
   protected void onPause() {
        //beaconManager.stopRanging(region);

       super.onPause();
   }
}

MyApplication.java

package com.example.estimotetest;

import android.app.Application;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.estimote.sdk.Beacon;
import com.estimote.sdk.BeaconManager;
import com.estimote.sdk.Region;

import java.util.List;
import java.util.UUID;

public class MyApplication extends Application {
    private BeaconManager beaconManager;
   @Override
   public void onCreate() {
        super.onCreate();
       beaconManager = new BeaconManager(getApplicationContext());

       beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
            @Override
           public void onServiceReady() {
                beaconManager.startMonitoring(new Region(
                        "monitored region",
                       UUID.fromString("b9407f30-f5f8-466e-aff9-25556b57fe6d"),
                       null, null));
           }
        });

       beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() {
            @Override
           public void onEnteredRegion(Region region, List<Beacon> list) {
                showNotification("in","in");
           }

            @Override
           public void onExitedRegion(Region region) {
                showNotification("out","out");

           }
        });

   }

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
   buildToolsVersion "29.0.2"
   defaultConfig {
        applicationId "com.example.estimotetest"
       minSdkVersion 18
       targetSdkVersion 29
       versionCode 1
       versionName "1.0"
       testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
   }
    buildTypes {
        release {
            minifyEnabled false
           proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
       }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
   implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
   testImplementation 'junit:junit:4.12'
   androidTestImplementation 'androidx.test.ext:junit:1.1.1'
   androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

   implementation 'com.estimote:sdk:0.10.8@aar'
}

Manifest

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
0

There are 0 best solutions below