0

Due to the problem mentioned here, I configure the mornitoring example code as follows, however my app can not detect the iBeacon advertiser deployed.

  1. new a mornitoring Activity named MainActivity, except the onCreate method, all other code are the same as the sample code.
public class MainActivity extends Activity implements BeaconConsumer {
    protected static final String TAG = "MornitoringActivity";
    public static final String UUID = "UUID: D57092AC-DFAA-446C-8EF3-C81AA22815B5";
    private BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
    TextView mInfoView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mInfoView = (TextView) findViewById(R.id.show_info_lable);
    beaconManager.setDebug(true);
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
    beaconManager.bind(this);
    Log.i(TAG, "on create complete!"); 
}
@Override 
protected void onDestroy() {
    super.onDestroy();
    beaconManager.unbind(this);
    Log.i(TAG, "on destroy complete!"); 
}
@Override
public void onBeaconServiceConnect() {
    beaconManager.setMonitorNotifier(new MonitorNotifier() {
    @Override
    public void didEnterRegion(Region region) {
        Log.i(TAG, "I just saw an beacon for the first time!"); 
        mInfoView.setText("I just saw an beacon for the first time!"); 
    }

    @Override
    public void didExitRegion(Region region) {
        Log.i(TAG, "I no longer see an beacon");
        mInfoView.setText("I no longer see an beacon");
    }

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

    try {
        beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", Identifier.parse(UUID), null, null));
    } catch (RemoteException e) {   }
}

}

  1. copy class.jar in android-beacon-library/libs/ into myProject/libs/, and add it to build path

  2. manually edit the AndroidManifest.xml, here is my xml file,

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mymornitoring"
    android:versionCode="1"
    android:versionName="1.0" >
    
    <uses-sdk
        android:minSdkVersion="18"
        android:targetSdkVersion="21" />
    
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    
    <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:enabled="true" 
        android:exported="true" 
        android:isolatedProcess="false" 
        android:label="beacon" 
        android:name="org.altbeacon.beacon.service.BeaconService">
    </service>
    <service 
        android:enabled="true" 
        android:name="org.altbeacon.beacon.BeaconIntentProcessor">
    </service>
    
    <receiver android:name="org.altbeacon.beacon.startup.StartupBroadcastReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
            <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
            <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
        </intent-filter>
    </receiver>
    </application>
    

  3. Use Macbook running the BeaconOSX app to perform as an iBeacon advertiser.(And I've use the AirLocate app on iPhone 4s to confirm the iBeacon advertiser works, however fail to be detected by the iBeacon Locate android app developed by Radius Networks)

  4. Then I ran myProject on Nexus 5, the logcat messages are as below

11-06 10:49:08.838: I/BeaconService(5023): beaconService version 2.0 is starting up
11-06 10:49:08.878: D/BeaconService(5023): No org.altbeacon.beacon.SimulatedScanData class exists.
11-06 10:49:08.878: I/BeaconService(5023): binding
11-06 10:49:08.908: I/BeaconService(5023): start monitoring received
11-06 10:49:08.908: D/BeaconService(5023): startMonitoring called
11-06 10:49:08.908: D/BeaconService(5023): Currently monitoring 1 regions.
11-06 10:49:08.928: D/BeaconService(5023): Waiting to stop scan for another 1100 milliseconds
11-06 10:49:08.928: D/BeaconService(5023): Scan started
11-06 10:49:09.938: D/BeaconService(5023): Waiting to stop scan for another 99 milliseconds
11-06 10:49:10.038: D/BeaconService(5023): Done with scan cycle
11-06 10:49:10.048: D/BeaconService(5023): Restarting scan.  Unique beacons seen last cycle: 0 Total beacon advertisement packets seen: 0

This idicate the BeaconService works well.

11-06 10:48:41.238: D/BtGatt.GattService(1483): registerClient() - UUID=6eaaf541-90fb-4e88-a0d5-1f267769128b
11-06 10:48:41.248: D/BtGatt.GattService(1483): onClientRegistered() - UUID=6eaaf541-90fb-4e88-a0d5-1f267769128b, clientIf=5
11-06 10:48:41.248: D/BtGatt.GattService(1483): startScan() - queue=0
11-06 10:48:41.248: D/BtGatt.GattService(1483): startScan() - adding client=5
11-06 10:48:51.258: D/BtGatt.GattService(1483): stopScan() - queue=1
11-06 10:48:51.258: D/BtGatt.GattService(1483): stopScan() - queue empty; stopping scan
11-06 10:48:51.258: D/BtGatt.GattService(1483): unregisterClient() - clientIf=5


11-06 10:48:41.238: D/BluetoothAdapter(1365): startLeScan(): null
11-06 10:48:41.248: D/BluetoothAdapter(1365): onClientRegistered() - status=0 clientIf=5    
11-06 10:48:51.258: D/BluetoothAdapter(1365): stopLeScan()    
11-06 10:49:08.918: D/BluetoothAdapter(5023): startLeScan(): null    
11-06 10:49:08.928: D/BluetoothAdapter(5023): onClientRegistered() - status=0 clientIf=5    
11-06 10:49:10.038: D/BluetoothAdapter(5023): stopLeScan()    
11-06 10:49:10.048: D/BluetoothAdapter(5023): startLeScan(): null    

I notice that there are two apps on my Nexus 5, who print the same BluetoothAdapter log msgs. Does this matter? And the didEnterRegion/didExitRegion has never been called. What could the problem be?

4

0 回答 0