2017-08-16 2 views
0

J'ai déjà utilisé un didacticiel et la bibliothèque Android Beacon (exemple de code). Malheureusement, mes applications ne peuvent pas trouver mes Beacons (Blueup). Je ne sais pas s'il y a une erreur dans ma configuration.Bibliothèque Altbeacon: impossible de trouver des balises

J'ai testé toutes les différentes expressions Beaconparser, avec les ID de mes Beacons. A la fin, j'ai décidé de changer le Identifier.parse ("...") en null, pour voir tous les Beacons. Parce que j'utilise un Android 6+ et SDK 23, j'ai ajouté ACCESS_COARSE_LOCATION et les autorisations Bluetooth.

Voici le message que je reçois: "MonitoringActivity: Je viens de passer de la vue/ne pas voir les balises: 0".

Ceci est mon code:

package com.example.smi.beacon03; 

import android.app.Activity; 
import android.os.RemoteException; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.Log; 

import org.altbeacon.beacon.Beacon; 
import org.altbeacon.beacon.BeaconConsumer; 
import org.altbeacon.beacon.BeaconManager; 
import org.altbeacon.beacon.BeaconParser; 
import org.altbeacon.beacon.Identifier; 
import org.altbeacon.beacon.MonitorNotifier; 
import org.altbeacon.beacon.RangeNotifier; 
import org.altbeacon.beacon.Region; 

import java.util.Collection; 

public class BeaconMainActivity extends Activity implements BeaconConsumer { 

protected static final String TAG = "MonitoringActivity"; 
protected static final String TAG2 = "RangingActivity"; 
public static final String ALTBEACON = "m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"; 
public static final String ALTBEACON2 = "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"; 
public static final String EDDYSTONE_TLM = "x,s:0-1=feaa,m:2-2=20,d:3-3,d:4-5,d:6-7,d:8-11,d:12-15"; 
public static final String EDDYSTONE_UID = "s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19"; 
public static final String EDDYSTONE_URL = "s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-20v"; 
public static final String IBEACON = "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"; 


private BeaconManager beaconManager; 

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

    beaconManager = BeaconManager.getInstanceForApplication(this); 

    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.URI_BEACON_LAYOUT)); 

    beaconManager.bind(this); 
} 

@Override 
protected void onDestroy() { 
    super.onDestroy(); 
    beaconManager.unbind(this); 
} 

@Override 
public void onBeaconServiceConnect() { 

    beaconManager.addMonitorNotifier(new MonitorNotifier() { 
     @Override 
     public void didEnterRegion(Region region) { 
      Log.i(TAG, "I just saw an beacon for the first time!"); 
     } 

     @Override 
     public void didExitRegion(Region region) { 
      Log.i(TAG, "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); 
     } 
    }); 

    beaconManager.addRangeNotifier(new RangeNotifier() { 
     @Override 
     public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) { 
      if (beacons.size() > 0) { 
       Log.i(TAG2, "The first beacon I see is about "+beacons.iterator().next().getDistance()+" meters away."); 
      } 
     } 
    }); 

    try { 
     beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null)); 
    } catch (RemoteException e) { } 
    try { 
     beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null)); 
    } catch (RemoteException e) { 
     e.printStackTrace(); 
    } 
} 

@Override 
public void onPointerCaptureChanged(boolean hasCapture) { 

} 
} 

Répondre

0

vous devez ajouter toutes vos mises en page de balises que vous avez été initialisées en haut de votre classe. alors faites quelque chose comme ceci:

beaconManager.getBeaconParsers().add(BeaconParser().setBeaconLayout(ALTBEACON); 
beaconManager.getBeaconParsers().add(BeaconParser().setBeaconLayout(ALTBEACON2); 
beaconManager.getBeaconParsers().add(BeaconParser().setBeaconLayout(EDDYSTONE_TLM); 
beaconManager.getBeaconParsers().add(BeaconParser().setBeaconLayout(EDDYSTONE_UID); 
beaconManager.getBeaconParsers().add(BeaconParser().setBeaconLayout(EDDYSTONE_URL); 
beaconManager.getBeaconParsers().add(BeaconParser().setBeaconLayout(IBEACON); 
+0

merci, avions ceci avant. C'est étrange de dire que ça marche sur mon portable avec le même code. –