I am designing an android app that uses android 4.3 can connect Bluetooth LE 4.0 devices, and I want to know that rssi, so my MainActivity has already get rssi's value,but only numbers, I try to let those number become progress percent, but it's not working?
my get rssi's value function :
public void run(){
int realRssi = rssi+100;
mDeviceRssi = ressi + "db" ;
mDeviceRssiView.setText(mDeviceRssi);
}
now,here is my question:
public class sending_thread extends Thread{
public void run(){
try{
while(true){
int progress = Integer.parseInt(mDeviceRSSI);
int[] int_progress = new int[1];
int_progress[0] = progress;
MainActivity.handler.sendMessage(MainActivity.handler.obtainMessage(1,int_progress));
Thread.sleep(1000);
}
}
catch(Exception e){}
}
}
but int progress = Integer.parseInt(mDeviceRSSI) is not working.
private void seekCircle(){
SeekCircle seekCircle = (SeekCircle) findViewById(R.id.seekCircle);
try{
handler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 1:
int[] receive_obj = (int[]) msg.obj;
updateText(receive_obj[0]);
break;
}
}
};
}catch (Exception e) {
Log.d("Handler exception", e.toString());
}
send_thread = new sending_thread();
send_thread.start();
}
it's my mistake,the code should be like this:
mDeviceRSSI = rssi + " db";
mDeviceRssiView.setText(mDeviceRSSI);
int progress = Integer.parseInt(mDeviceRSSI); //error
int[] int_progress = new int[1];
int_progress[0] = progress;
I know mDeviceRSSI is String, but I don't know how to transform String into int?
It looks like your attribute mDeviceRssi
contains characters:
mDeviceRssi = ressi + "db"
and later you do:
int progress = Integer.parseInt(mDeviceRSSI);
That's not working.