iBeacon从服务器设置区域和元数据

时间:2014-10-28 17:58:07

标签: json ibeacon ibeacon-android android-ibeacon

我为Beacon管理创建了Web管理界面,用户可以输入他们的Majorid&具有相应信息的Minorid(元数据)。请看一下JSON。我从问题中提到的URL中获取了JSON值。但是我如何为不同的信标创建一组区域。仍然混淆为不同的信标创建区域,因为信标将从服务器后端添加。

JSON:

 [{"name":"Test","uuid":"B9407F30-F5F8-466E-AFF9-25556B57FE6D","major_id":"23695","minor_id":"46901","notification":"","type":"Image","product_image":"www.justdoonce.com/beacon/staging/images/product_images/visualize2.png"},

{"name":"Test1","uuid":"B9407F30-F5F8-466E-AFF9-25556B57FE6D","major_id":"42583","minor_id":"41770","notification":"","type":"Text","text_text":"<p>test</p>"}]

解析&amp;分配:

     major_id= Integer.parseInt(jObject.getString("major_id")) ;

     minor_id= Integer.parseInt(jObject.getString("minor_id")) ;

region_server = new Region("region_server", uuid, major_id, minor_id);  //creating region

 public void onEnteredRegion(final Region region, List<Beacon> beacons) {

     if (region.getIdentifier().equals("region_server")) { 

               notify_image.setVisibility(View.VISIBLE);

   }


          }

1 个答案:

答案 0 :(得分:0)

如果您使用的是Android Beacon Library,您只需在循环中构建区域,如下所示:

String refId = id+"_"+id_major+"_"+id_minor;
Region region = new Region(refId,Identifier.parse(id),
                       Identifier.parse(id_major), Identifier.parse(id_minor));

refId是一个唯一的字符串,每个区域必须不同。