2014-09-29 2 views
1

Я хотел бы использовать библиотеку AltBeacon для обнаружения тега RadBeacon из Radius Networks. Чтобы понять, как работает библиотека, я хотел бы использовать ссылочное приложение AltBeacon.Использование AltBeacon

Я применил this code в своем примере приложения. После добавления библиотеки AltBeacon в проект я могу запустить проект.

Как я уже упоминал ранее, я хотел бы обнаружить теги RadBeacon IBeacons от Radius Networks. Я знаю, что мне нужно использовать BeaconParser. Мой вопрос - как выглядит BeaconParser для тега RadBeacon. Here - это анализатор IBeacon для оценочных маяков.
Когда я отлаживать этот проект и посмотреть внутрь LogCat я могу увидеть следующие сообщения:

"Beacon detected: id1: "UUID of RadBeacon" id2= "Major of RadBeacon" id3:"Minor of RadBeacon"". 
"looking for ranging region mathes for this beacon" 
"got record" 
"This is not a matching Beacon advertisment." 

Как мне нужно изменить BeaconParser? Вот мой исходный код

public class FindRadBeaconActivity extends ActionBarActivity implements BeaconConsumer{ 
private BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this); 
protected static final String TAG = "RangingActivity"; 

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

    // check bluetooth 
    verifyBluetooth(); 

    beaconManager.getBeaconParsers().add(new BeaconParser(). 
      setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24")); 
    beaconManager.debug = true; 
    beaconManager.bind(this); 

} 

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



@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.find_rad_beacon, 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 onBeaconServiceConnect() { 
    beaconManager.setMonitorNotifier(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);  
    } 
    }); 

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

private void verifyBluetooth() { 

    try { 
     if (!BeaconManager.getInstanceForApplication(this).checkAvailability()) { 
      final AlertDialog.Builder builder = new AlertDialog.Builder(this); 
      builder.setTitle("Bluetooth not enabled");   
      builder.setMessage("Please enable bluetooth in settings and restart this application."); 
      builder.setPositiveButton(android.R.string.ok, null); 
      builder.setOnDismissListener(new DialogInterface.OnDismissListener() { 
       @Override 
       public void onDismiss(DialogInterface dialog) { 
        finish(); 
        System.exit(0);     
       }     
      }); 
      builder.show(); 
     }   
    } 
    catch (RuntimeException e) { 
     final AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setTitle("Bluetooth LE not available");   
     builder.setMessage("Sorry, this device does not support Bluetooth LE."); 
     builder.setPositiveButton(android.R.string.ok, null); 
     builder.setOnDismissListener(new DialogInterface.OnDismissListener() { 

      @Override 
      public void onDismiss(DialogInterface dialog) { 
       finish(); 
       System.exit(0);     
      } 

     }); 
     builder.show(); 

    } 

} 

}

ответ

0

Если вы ищете RadBeacon Layout, используйте приведенную ниже схему

mBeaconManager 
      .getBeaconParsers() 
      .add(new BeaconParser() 
        .setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25")); 
Смежные вопросы