Una baliza, miles de apps

Nuestras balizas son reutilizables por otras apps que necesiten un check-in verificado

Primeros pasos - Android

En menos de lo que dura un café puedes tener tu App funcionando con el Outbarriers SDK

1. Instala la libreria

Añade a tu build.gradle la librería

android {
    repositories {
        maven {
            url "https://outbarriers.com/sdk/repository/"
        }
    }
}
dependencies {

    compile('com.outbarriers:outbarrierssdk:1.2.0:release@aar') {
        transitive = true;
    }
}
Si lo prefieres puedes descarga la última versión del SDK (.aar)
Atención Próximamente estará disponible en los repositorios de Maven y el código fuente estará disponible en GitHub

2. Añade tus credenciales de acceso

Dentro de la sección <application> del AndroidManifest.xml, añade el API KEY y API SECRET que te hemos facilitado para tu App.
<meta-data android:name="com.outbarriers.sdk.API_KEY" android:value="TU_API_KEY" />
<meta-data android:name="com.outbarriers.sdk.API_SECRET" android:value="TU_API_SECRET" />

3. Integra los callbacks en tu actividad

public class YourActivity extends AppCompatActivity implements OutbeaconListener {

    private OutbarriersManager oManager;
    private final int PERMISSION_REQUEST_COARSE_LOCATION = 0x123;
    ...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ...
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && this.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("App need location permission");
            builder.setMessage("To detect beacons is necessary that you allow the location permission.");
            builder.setPositiveButton(android.R.string.ok, null);
            builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @TargetApi(Build.VERSION_CODES.M)
                public void onDismiss(DialogInterface dialog) {
                    requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);
                }
            });
            builder.show();
        } else {
            initOBManager();
        }
    }
    private void initOBManager() {
      OutbarriersManager.getManager(this, new OutbarriersManagerListener() {
              @Override
              public void onSuccess(OutbarriersManager ob) {
                  oManager = ob;
                  oManager.setOnOutbeaconDetected(YourActivity.this);
                  oManager.setGPSEnabled(false);
                  oManager.startDetection();
              }

              @Override
              public void onError(OutbarriersManagerError err) {
                // Handle OutbarriersManager error
              }
          });

    }
    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        switch (requestCode) {
            case PERMISSION_REQUEST_COARSE_LOCATION: {
                if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    initOBManager();
                } else {
                  // Handle no permission location context
                }
                return;
            }
        }
    }

    @Override
    public void onOutbeaconDetected(OutbeaconMatch od) {
        Toast.makeText(getApplicationContext(), "Outbeacon detected: " + od.outbeacon.uuid, Toast.LENGTH_LONG).show();
    }

    @Override
    public void onDetectionError(OutbarriersError error) {
    	// Handle Outbarriers Beacon detection error
    }

    @Override
    public void onNearestBeacons(OutbeaconList outbeaconList) {
      // Handle nearest beacons
    }

    @Override
    public void onScanningStatus(boolean b) {
      // Handle scanning status
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (oManager != null) {
            oManager.onDestroy();
        }
    }
}