I'm currently developing an Android app on Android Studio to detect and use iBeacons. The part where I have to detect the beacon and get his parameters is done but I'm facing issues to change the value of this parameters for a specific iBeacon with the APIs that are available on the Android system. I've seen that different functions like setId1 (UUID), setId2 (Major), setId3 (Minor) on the Beacon.Builder() class can be use to modify the values but I'm a little bit lost to know how to use this functions on an specific Beacon.
This is the definition of my class that I've created for the 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; }
}
This is the code to get the different values of the iBeacon's parameters :
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));
And this is the declaration of my ArrayAdapter to deal with the display of my iBeacon's parameters for my view :
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;
}