Android Studio Estimote Beacon应用程序

时间:2015-02-12 21:15:28

标签: android ibeacon ibeacon-android android-ibeacon

我试图在android studio中制作基本的灯塔应用程序。我只是想扫描信标并将它们列入屏幕。这是我的代码。我是从某个地方带走的。

public class MainActivity extends ActionBarActivity {

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

private BeaconManager beaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    beaconManager.setRangingListener(new BeaconManager.RangingListener() {
        @Override public void onBeaconsDiscovered(Region region, List<Beacon> beacons) {
            Log.d("TAG", "Ranged beacons: " + beacons);
        }
    });
}

@Override
protected void onStart() {
    super.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();
}
}

这是我的manifest.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.oem.estimote_ibeacon_app" >
    <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.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <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"/>
    </application>
</manifest>

当我打开应用程序时,它说&#34;停止&#34;请帮忙。我有信标进行测试。我的错误在哪里?谢谢。

1 个答案:

答案 0 :(得分:0)

似乎是

中的ALL_ESTIMOTE_BEACONS
beaconManager.startRanging(ALL_ESTIMOTE_BEACONS);

为空。

中输入有效的regionid而不是“regionid”
private static final Region ALL_ESTIMOTE_BEACONS = new Region("regionId", null, null, null);