Класс связи:-
Код: Выделить всё
private ExecutorService executor = Executors.newSingleThreadExecutor();
private Handler handler = new Handler(Looper.getMainLooper());
public String genAuthToken(String userName, String passwd) throws Exception{
if(!connected)return null;
JSONObject json = new JSONObject();
json.put("func","genAuthToken");
json.put("userName",userName);
json.put("passwd",passwd);
JSONObject finalJSON = json;
final String[] reply = {""};
pw.println(finalJSON);
reply[0] = scan.nextLine();
json = new JSONObject(reply[0]);
if((int) json.get("code") == 200){
this.authToken = json.get("authToken").toString();
return (String) json.get("authToken");
}
return String.valueOf((int) json.get("code"));
}
Код: Выделить всё
LedGo client = new LedGo();
boolean connected = client.connect("192.168.1.4",1304,cf,()->{},()->{Snackbar.make(view,"Couldn't connect to server",Snackbar.LENGTH_SHORT).setAnchorView(R.id.fab).show();});
String authToken = client.genAuthToken("userName","passwd",true,()->{},()->{});
Как получить некоторые значения из функции ExecutorService.execute() в Android Development, Java
Подробнее здесь: https://stackoverflow.com/questions/786 ... -with-exec