如何通过Android上的SDK

时间:2017-04-21 07:57:53

标签: java android ibeacon beacon android-ibeacon

我目前正在Android Studio上开发Android应用以检测​​和使用iBeacons。我必须检测信标并获取其参数的部分已完成,但我面临的问题是使用Android系统上可用的API更改特定iBeacon的此参数的值。我已经看到Beacon.Builder()类中的setId1(UUID),setId2(Major),setId3(Minor)等不同的函数可用于修改值但我知道有点丢失了如何在特定的Beacon上使用此功能。

这是我为Beacon创建的班级定义:

class IdBeacon {
    private String UUID;
    private String Major;
    private String Minor;
    private String Distance;
    private String RSSI;
    private String TxPower;

    public IdBeacon (String UUID, String Major, String Minor, String Distance, String RSSI, String TxPower){
        this.UUID = UUID;
        this.Major = Major;
        this.Minor = Minor;
        this.Distance = Distance;
        this.RSSI = RSSI;
        this.TxPower = TxPower;
    }

    public String getUUID() { return UUID; }
    public void setUUID(String UUID) { this.UUID = UUID; }

    public String getMajor() { return Major; }
    public void setMajor(String major) { Major = major; }

    public String getMinor() { return Minor; }
    public void setMinor(String minor) {  Minor = minor;  }

    public String getDistance() { return Distance;  }
    public void setDistance(String distance) { Distance = distance }

    public String getRSSI() { return RSSI; }
    public void setRSSI(String RSSI) { this.RSSI = RSSI; }

    public String getTxPower() { return TxPower; }
    public void setTxPower(String txPower) { this.TxPower = txPower; }
}

这是获取iBeacon参数的不同值的代码:

String distance =  String.valueOf(beacons.iterator().next().getDistance());
String Uuid = String.valueOf(beacons.iterator().next().getId1());
String major = String.valueOf(beacons.iterator().next().getId2());
String minor = String.valueOf(beacons.iterator().next().getId3());
String Rssi = String.valueOf(beacons.iterator().next().getRssi());
String TxPower = String.valueOf(beacons.iterator().next().getTxPower());

arrayIdBeacon.clear();
arrayIdBeacon.add(new IdBeacon(Uuid,major,minor,distance,Rssi,TxPower));

这是我的ArrayAdapter的声明,用于处理我的iBeacon参数的显示:

public BeaconAdapter(Context context, ArrayList<IdBeacon> idBeacons){
    super(context, 0,idBeacons);
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

    IdBeacon beacon = getItem(position);

    if (convertView == null){
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.mylist, parent, false);
    }

    TextView tvUuid = (TextView) convertView.findViewById(R.id.ValUUID);
    TextView tvMajor = (TextView) convertView.findViewById(R.id.ValMajor);
    TextView tvMinor = (TextView) convertView.findViewById(R.id.ValMinor);
    TextView tvDist = (TextView) convertView.findViewById(R.id.ValDist);
    TextView tvRSSI = (TextView) convertView.findViewById(R.id.ValRSSI);
    TextView tvTxPower = (TextView) convertView.findViewById(R.id.tvTxPower);

    if (beacon != null){
        tvUuid.setText(beacon.getUUID());
        tvMajor.setText(beacon.getMajor());
        tvMinor.setText(beacon.getMinor());
        tvDist.setText(beacon.getDistance());
        tvRSSI.setText(beacon.getRSSI());
        tvTxPower.setText(beacon.getTxPower());
    }

    return convertView;
}

1 个答案:

答案 0 :(得分:0)

Android Beacon Library中的Beacon.Builder()类用于构建新的信标对象,以便从Android设备本身传输信标广告。

库中不支持更改外部硬件信标配置,例如,更改次要信息。这是事实,因为没有这样做的标准机制。每个信标硬件制造商都有自己的系统来更改配置,其中许多是专有的和未记录的。

结论:要以编程方式更改硬件信标配置,您需要来自信标供应商的特定SDK。