I've the same problem as this Android Emitter.Listener not working question but the given answer in that question was not helpful and I couldn't even find any solution .Can anyone please help me to solve this?
Here in my code I'm sending base64 string to node.js server which saves the file and sending the link back to me (The file saving is working fine).Even the link is not toasted.
My Code is:
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
socket.connect();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
socket.on("data", handleIncomingMessage);
}
});}
//Onclick of a button
JSONObject obj=new JSONObject();
try {
obji.put("profile_pic",image);
socket.emit("data",obji);
} catch (JSONException e) {
e.printStackTrace();
}
private Emitter.Listener handleIncomingMessage = new Emitter.Listener(){
@Override
public void call(final Object... args){
Toast.makeText(getActivity().getApplicationContext(),"Hello India",Toast.LENGTH_LONG).show();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
JSONObject data = (JSONObject) args[0];
//JSONObject d=(JSONObject) args[1];
String imgLink;
try {
imgLink = data.getString("data").toString();
Glide.with(getContext()).load(imgLink).asBitmap().dontAnimate().into(imageView);
Toast.makeText(getActivity().getApplicationContext(),imgLink,Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Toast.makeText(getActivity().getApplicationContext(),e.toString(),Toast.LENGTH_LONG).show();
}
}
});
}
};