IBeacon Android无法识别信标

时间:2014-05-01 11:13:13

标签: ibeacon-android android-ibeacon

我有mac,我已经获得了macbeacon。

我已经下载了免费的IBeacon for Android库,我正在尝试编写一个基本活动,在范围内显示一次吐司,但它不起作用......这就是我所做的:

import android.os.Bundle;
import android.os.RemoteException;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.radiusnetworks.ibeacon.IBeaconConsumer;
import com.radiusnetworks.ibeacon.IBeaconManager;
import com.radiusnetworks.ibeacon.MonitorNotifier;
import com.radiusnetworks.ibeacon.Region;

public class iBeaconLocate extends ActionBarActivity implements IBeaconConsumer{

    protected static final String TAG = "RangingActivity";
    private IBeaconManager iBeaconManager = IBeaconManager.getInstanceForApplication(this);

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

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.i_beacon_locate, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onIBeaconServiceConnect() {
        iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
            @Override
            public void didEnterRegion(Region region) {

                String test = region.getProximityUuid();

                Toast.makeText(getApplicationContext(), "Beacon: " + test + " found", Toast.LENGTH_LONG).show();
            }

            @Override
            public void didExitRegion(Region region) {
                Toast.makeText(getApplicationContext(), "Beacon: "+ region.getProximityUuid() +" lost", Toast.LENGTH_LONG).show();

            }

            @Override
            public void didDetermineStateForRegion(int state, Region region) {
                Log.i(TAG, "I have just switched from seeing/not seeing iBeacons: " + state);
            }
        });

        try {
            iBeaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
        } catch (RemoteException e) {   }
    }
}

如果有人能看到他的任何错误,我会很感激输入,因为我不确定它是否真的意味着这么简单?

我在Android工作室工作,我按照quick startup guide按照指示对其进行了配置...请,任何帮助表示赞赏

提前致谢

1 个答案:

答案 0 :(得分:0)

代码缺少绑定到iBeaconManager的调用。试试这个:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_i_beacon_locate);
    iBeaconManager.bind(this);
}