0

我使用 estimote android sdk 进行检测或扫描,但我没有得到信标和列表调用。我根据 lib 上显示的自述文件设置我的代码并编译代码,但没有得到 becons。

https://github.com/Estimote/Android-SDK

private static final String ESTIMOTE_PROXIMITY_UUID = "B9407F30-F5F8-466E-AFF9-25556B57FE6D";
      private static final Region ALL_ESTIMOTE_BEACONS = new Region("regionId", ESTIMOTE_PROXIMITY_UUID, null, null);
      private BeaconManager beaconManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_signup);


        beaconManager = new BeaconManager(SignupActivity.this);
        // Should be invoked in #onCreate.
          beaconManager.setRangingListener(new BeaconManager.RangingListener() {

            @Override
            public void onBeaconsDiscovered(Region arg0, List<Beacon> beacons) {
                 Log.d("TAG", "Ranged beacons: " + beacons);
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
         // Should be invoked in #onStart.
          beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
            @Override 
            public void onServiceReady() {
              try {
                beaconManager.startRanging(ALL_ESTIMOTE_BEACONS);
              } catch (RemoteException e) {
                Log.e("TAG", "Cannot start ranging", e);
              }
            }
          });
    }

    @Override
    protected void onStop() {
        super.onStop();
        try {
            beaconManager.stopRanging(ALL_ESTIMOTE_BEACONS);
          } catch (RemoteException e) {
            Log.e("TAG", "Cannot stop but it does not matter now", e);
          }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
          beaconManager.disconnect();
    }
4

2 回答 2

0

改变

private static final Region ALL_ESTIMOTE_BEACONS = new Region("regionId", ESTIMOTE_PROXIMITY_UUID, null, null);        

private static final Region ALL_ESTIMOTE_BEACONS = new Region("regionId", null, null, null);        

也改变

        beaconManager = new BeaconManager(SignupActivity.this);
    // Should be invoked in #onCreate.
      beaconManager.setRangingListener(new BeaconManager.RangingListener() {

        @Override
        public void onBeaconsDiscovered(Region arg0, List<Beacon> beacons) {
             Log.d("TAG", "Ranged beacons: " + beacons);
        }
    });

        beaconManager = new BeaconManager(SignupActivity.this);
    // Should be invoked in #onCreate.
      beaconManager.setRangingListener(new BeaconManager.RangingListener() {

        @Override
        public void onBeaconsDiscovered(Region arg0, List<Beacon> beacons) {
             Log.d("TAG", "Ranged beacons: " + beacons.size());
        }
    });

在这里你可以看到附近信标的大小

于 2014-11-01T06:31:28.357 回答
0

下载jar文件。
https://github.com/Estimote/Android-SDK https://github.com/Estimote/Android-SDK/blob/master/EstimoteSDK/estimote-sdk-preview.jar

主宴代码。

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.app"
        android:versionCode="1"
        android:versionName="1.0" >

        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="18" />

        <uses-permission android:name="android.permission.BLUETOOTH" />
        <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

        <application
            android:allowBackup="true"
            android:icon="@drawable/app_icon"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >

            <activity
                android:name="com.example.user.TempActivity"
                android:configChanges="orientation|screenSize"
                android:label="@string/app_name"
                android:windowSoftInputMode="stateHidden|adjustPan" >

                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>

            </activity>

            <service
                android:name="com.estimote.sdk.service.BeaconService"
                android:exported="false" >
            </service>
        </application>

    </manifest>


    // Example activity
     public class TempActivity extends Activity {

            private static final String ESTIMOTE_PROXIMITY_UUID = "B9407F30-F5F8-466E-AFF9-25556B57FE6D";
            private static final Region ALL_ESTIMOTE_BEACONS = new Region("regionId", ESTIMOTE_PROXIMITY_UUID, null, null);

            private BeaconManager beaconManager;


            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                requestWindowFeature(Window.FEATURE_NO_TITLE);
                setContentView(R.layout.temp_activity);
                startBeaconDetectionService();

                WebAsynk mWebAsynk= new WebAsynk();
                mWebAsynk.execute(BEACON_WEB_SERVICE);
            }

            @Override
            protected void onStart() {
                super.onStart();
                // Should be invoked in #onStart.
                beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
                    @Override 
                    public void onServiceReady() {
                        try {
                            beaconManager.startRanging(ALL_ESTIMOTE_BEACONS);
                        } catch (RemoteException e) {
                            Log.e("TAG", "Cannot start ranging", e);
                        }
                    }
                });
            }

            @Override
            protected void onStop() {
                super.onStop();
                try {
                    beaconManager.stopRanging(ALL_ESTIMOTE_BEACONS);
                } catch (RemoteException e) {
                    Log.e("TAG", "Cannot stop but it does not matter now", e);
                }
            }
            @Override
            protected void onDestroy() {
                super.onDestroy();
                beaconManager.disconnect();
            }


            /**
             * Beacon Detection Service response handle here
             */
            private void startBeaconDetectionService(){
                beaconManager = new com.estimote.sdk.BeaconManager(TempActivity.this);
                beaconManager.setForegroundScanPeriod(2000,2000);
                // Should be invoked in #onCreate.
                beaconManager.setRangingListener(new com.estimote.sdk.BeaconManager.RangingListener() {

                    @Override
                    public void onBeaconsDiscovered(Region arg0, final List<Beacon> beacons) {
                        Log.d("TAG", "Ranged beacons: " + beacons);
                        Log.e("TAG", "Ranged beacons: " + beacons);

                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                int test=0;
                                if(beacons.size()<=0){
                                    Toast.makeText(TempActivity.this, "No beacon found",
                                            Toast.LENGTH_SHORT).show();
                                }else{

                                    for (int i = 0; i < beacons.size(); i++) {
                                        String beac=beacons.get(i).getProximityUUID();
                                        String macAddress=beacons.get(i).getMacAddress();
                                        int major=beacons.get(i).getMajor();
                                        int minor=beacons.get(i).getMinor();
                                        int rssi=beacons.get(i).getRssi();
                                        // Filter for right beacon detection




                                                Toast.makeText(TempActivity.this, "I found a beacon with UUID; "+beac+" M-"+major,
                                                        Toast.LENGTH_SHORT).show();

                                    }


                                }                       
                            }
                        });
                    }
                });
            }
            }
于 2014-11-12T13:09:34.937 回答