Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.chemnote.zheev.golos;
- import android.util.Log;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.Objects;
- import okhttp3.Response;
- import okhttp3.WebSocket;
- import okhttp3.WebSocketListener;
- /**
- * Created by zheev on 07.03.18.
- */
- public class WebSocketGolos extends WebSocketListener {
- @Override
- public void onOpen(WebSocket webSocket, Response response) {
- try {
- JSONObject jsonObject = new JSONObject("{id:1, method:'call', 'params': ['database_api', 'set_block_applied_callback', [0] ]}");
- webSocket.send(jsonObject.toString());
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- @Override
- public void onMessage(WebSocket webSocket, String text)
- {
- try{
- JSONObject data = new JSONObject(text);
- String method = data.getString("method");
- Log.d("WS", method.toString());
- JSONArray params = data.getJSONArray("params");
- JSONArray objectParam = params.getJSONArray(1);
- JSONObject arrayObjectParam = objectParam.getJSONObject(0);
- String previousParam = arrayObjectParam.getString("previous");
- Integer hex = Integer.parseInt(previousParam.substring(0, 8), 16);
- Log.d("WS", hex.toString());
- if(Objects.equals(method, "notice")){
- Log.d("WS", data.toString());
- System.out.print(data);
- }
- }catch (JSONException e){
- e.toString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement