Question

J'utilise l'exemple d'application de référence de proximité-Android fourni par Radius Network pour détecter une iBeacon.J'ai un iPad configuré comme iBeacon et j'ai ajouté environ 3 régions de balise dans le kit de proximité.Le problème auquel je suis confronté en ce moment est que je ne parviens pas à récupérer le nom de Beacon et l'URL supplémentaire que j'avais dans le kit de proximité sous Android.

Je dois essentiellement afficher l'URL associée à la région de balise dans ce kit de proximité dans l'application Android, tout comme le fait l'application iOS.

Lors du débogage, j'avais vérifié que même après la détection de la balise dans l'application, le didEnterRegion n'est pas appelé. Je dois essentiellement enregistrer les détails de cette balise particulière dans la base de données une fois qu'elle est détectée.

L'application n'appelle pas non plus didExitRegion.

En publiant le code ci-dessous, faites-moi savoir ce que je fais de mal.

public class AndroidProximityReferenceApplication extends Application implements
        BootstrapNotifier {
    private static final String TAG = "AndroidProximityReferenceApplication";
    private RegionBootstrap regionBootstrap;
    private BackgroundPowerSaver backgroundPowerSaver;
    private boolean haveDetectedIBeaconsSinceBoot = false;

    public void onCreate() {
        super.onCreate();
        Log.d(TAG,
                "setting up background monitoring for iBeacons and power saving");

        // wake up the app when an iBeacon is seen
        Region region = new Region(
                "com.radiusnetworks.androidproximityreference.backgroundRegion",
                "2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6", null, null);
        regionBootstrap = new RegionBootstrap(this, region);

        // simply constructing this class and holding a reference to it in your
        // custom Application
        // class will automatically cause the iBeaconLibrary to save battery
        // whenever the application
        // is not visible. This reduces bluetooth power usage by about 60%
        backgroundPowerSaver = new BackgroundPowerSaver(this);
    }

    @Override
    public void didDetermineStateForRegion(int arg0, Region arg1) {
        // This method is not used in this example
    }

    @Override
    public void didEnterRegion(Region arg0) {
        // In this example, this class sends a notification to the user whenever
        // an iBeacon
        // matching a Region (defined above) are first seen.
        Log.d(TAG, "did enter region.");
        if (!haveDetectedIBeaconsSinceBoot) {
            Log.d(TAG, "auto launching MainActivity");

            // The very first time since boot that we detect an iBeacon, we
            // launch the
            // MainActivity
            Intent intent = new Intent(this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            // Important: make sure to add android:launchMode="singleInstance"
            // in the manifest
            // to keep multiple copies of this activity from getting created if
            // the user has
            // already manually launched the app.
            this.startActivity(intent);
            haveDetectedIBeaconsSinceBoot = true;
        } else {
            // If we have already seen iBeacons and launched the MainActivity
            // before, we simply
            // send a notification to the user on subsequent detections.
            Log.d(TAG, "Sending notification.");
            ParseObject beacon = new ParseObject("Beacon");
            beacon.put("beacon_name", arg0.getClass().getName());
            beacon.put("beacon_id", arg0.getUniqueId());
            beacon.put("device_type", "Android");
            beacon.put("device_UUID", android.os.Build.MODEL);
            beacon.put("beacon_status", "ENTRY");
            beacon.saveInBackground();

            sendNotification();
        }

    }

    @Override
    public void didExitRegion(Region arg0) {
        Log.d(TAG, "exited region");
        ParseObject beacon = new ParseObject("Beacon");
        beacon.put("beacon_name", arg0.getClass().getName());
        beacon.put("beacon_id", arg0.getUniqueId());
        beacon.put("device_type", "Android");
        beacon.put("device_UUID", android.os.Build.MODEL);
        beacon.put("beacon_status", "ENTRY");
        beacon.saveInBackground();

    }

    private void sendNotification() {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                this).setContentTitle("Proximity Reference Application")
                .setContentText("An iBeacon is nearby.")
                .setSmallIcon(R.drawable.ic_launcher);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(resultPendingIntent);
        NotificationManager notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(1, builder.build());

    }
}

Le code ci-dessous est du activité principale classe

public class MainActivity extends Activity implements IBeaconConsumer,
        RangeNotifier, IBeaconDataNotifier {
    public static final String TAG = "MainActivity";

    IBeaconManager iBeaconManager;
    Map<String, TableRow> rowMap = new HashMap<String, TableRow>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Parse.initialize(this, "test123",
                "test345");
        IBeaconManager.LOG_DEBUG = true;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        iBeaconManager = IBeaconManager.getInstanceForApplication(this
                .getApplicationContext());
        iBeaconManager.bind(this);
    }

    @Override
    public void onIBeaconServiceConnect() {
        Region region = new Region("MainActivityRanging", null, null, null);
        try {
            iBeaconManager.startRangingBeaconsInRegion(region);
            iBeaconManager.setRangeNotifier(this);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        iBeaconManager.unBind(this);
    }

    @Override
    public void didRangeBeaconsInRegion(Collection<IBeacon> iBeacons,
            Region region) {
        for (IBeacon iBeacon : iBeacons) {
            iBeacon.requestData(this);
            Log.d(TAG, "I see an iBeacon: " + iBeacon.getProximityUuid() + ","
                    + iBeacon.getMajor() + "," + iBeacon.getMinor());
            String displayString = iBeacon.getProximityUuid() + " "
                    + iBeacon.getMajor() + " " + iBeacon.getMinor() + "\n";
            displayTableRow(iBeacon, displayString, false);

        }
    }

    @Override
    public void iBeaconDataUpdate(IBeacon iBeacon, IBeaconData iBeaconData,
            DataProviderException e) {
        if (e != null) {
            Log.d(TAG, "data fetch error:" + e);
        }
        if (iBeaconData != null) {
            Log.d(TAG,
                    "I have an iBeacon with data: uuid="
                            + iBeacon.getProximityUuid() + " major="
                            + iBeacon.getMajor() + " minor="
                            + iBeacon.getMinor() + " welcomeMessage="
                            + iBeaconData.get("welcomeMessage"));
            String displayString = iBeacon.getProximityUuid() + " "
                    + iBeacon.getMajor() + " " + iBeacon.getMinor() + "\n"
                    + "Welcome message:" + iBeaconData.get("welcomeMessage");
            displayTableRow(iBeacon, displayString, true);
        }
    }

    private void displayTableRow(final IBeacon iBeacon,
            final String displayString, final boolean updateIfExists) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                TableLayout table = (TableLayout) findViewById(R.id.beacon_table);
                String key = iBeacon.getProximity() + "-" + iBeacon.getMajor()
                        + "-" + iBeacon.getMinor();
                TableRow tr = (TableRow) rowMap.get(key);
                if (tr == null) {
                    tr = new TableRow(MainActivity.this);
                    tr.setLayoutParams(new TableRow.LayoutParams(
                            TableRow.LayoutParams.WRAP_CONTENT,
                            TableRow.LayoutParams.WRAP_CONTENT));
                    rowMap.put(key, tr);
                    table.addView(tr);
                } else {
                    if (updateIfExists == false) {
                        return;
                    }
                }
                tr.removeAllViews();
                TextView textView = new TextView(MainActivity.this);
                textView.setText(displayString);
                tr.addView(textView);

            }
        });

    }

}

Toute aide serait appréciée Merci :)

Était-ce utile?

La solution

Lors de l'utilisation Kit de proximité pour Android, deux ensembles distincts d'API sont disponibles.Un ensemble utilise un ProximityKitManager, et il est destiné à des cas d'utilisation plus simples dans lesquels vous pouvez préconfigurer tous vos identifiants iBeacon et les données associées côté serveur, et laisser le ProximityKitManager gérer la configuration et la surveillance dans une classe d'application globale.

Le deuxième ensemble d'API utilise le IBeaconManager et fournir un contrôle plus fin.Mais parce que le ProximityKitManager utilise le IBeaconManager sous le capot, il ne faut pas utiliser les deux en même temps, car vous pouvez facilement casser la configuration automatique effectuée en ProximityKitManager.Je soupçonne que c'est ce qui cause votre problème, car le code utilise le ProximityKitManager dans la classe Application et IBeaconManager dans la classe Activité.Voir ici pour plus d'informations.

Si vous devez suivre les balises quels que soient les identifiants définis dans ProximityKit, mais que vous souhaitez tout de même accéder aux données configurées pour certaines iBeacons dans ProximityKit, vous ne devez pas utiliser l'option ProximityKitManager et à la place, utilisez simplement le IBeaconManager.Il existe une application de référence qui montre comment accéder aux données ProximityKit à l'aide de cette API disponible ici.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top