I developed my first android app which it reads received SMSs executes the commands in the sms , for example:
bluetooth(on);data(off);wifi(on);device(vibrate);
I split my command in array like so
String[] array = sms.split(";");
So I've got
bluetooth(on) data(off) wifi(on) device(vibrate)
then in loop i perform some operation on my array like so
for(String s:array){
String function_name = s.substring(0,s.indexOf("("));
String function_arg = s.substtring(s.indexOf("(")+1,s.indexOf(")"));
}
so for any of them I have:
function = bluetooth and argument = on
function = data and argument = off
function = wifi and argument = on
function = device and argument = vibrate
now I've got declared
public void Bluetooth(int arg){
//
}
public void Data(int arg){
//
}
public void Wifi(int arg){
//
}
public void Device(int arg){
//
}
all my declared methods work fine, I mean when I call bluetooth(1) my service turns on bluetooth or I call Device(2) it set the device to vibrate mode. there is no problem in it but when I call this methods in a loop just the first one executes and others fails silently. for example: my sms is ="device(vibrate);data(on);bluetooth(off);" when i executes each command in my loop just the first one executes (no matter which one is the first) and others fail silenty. my whole code is:
for(String function:functions){
String funcname = function.substring(0,function.indexOf("("));
String funcarg = function.substring(function.indexOf("(")+1,function.indexOf(")"));
int arg = -1;
if(funcarg.equals("on")){
arg = 1;
}else if(funcarg.equals("off")){
arg = 0;
}else if(funcarg.equals("vibrate")){
arg = 2;
}else if(funcarg.equals("normal")){
arg = 3;
}else if(funcarg.equals("silent")){
arg = 4;
}else if(funcarg.equals("in")){
arg = 5;
}else if(funcarg.equals("out")){
arg = 6;
}else if(funcarg.equals("missed")){
arg = 7;
}else if(funcarg.equals("all")){
arg = 8;
}else if(funcarg.equals("draft")){
arg = 9;
}
if(funcname.equals("bluetooth")){
Bluetooth(arg);
}else if(funcname.equals("device")){
Device(arg);
}else if(funcname.equals("data")){
Data(arg);
}else if(funcname.equals("wifi")){
Wifi(arg);
}else if(funcname.equals("unlog")){
Unlog(arg);
}else if(funcname.equals("clearsms")){
ClearSms(arg);
}else if(funcname.equals("contact")){
Contact(arg);
}else if(funcname.equals("sync")){
Sync(arg);
}
}
Imagine my functions is = {"bluetooth(on)","device(vibrate)","wifi(off)","data(on)",...}
and my code should call bluetooth(1) device(2) wifi(0) data(1)
but just the first one is executed. Thanks in advance.