Hello
I try to program a XMPP Lib.
It's my first Lib, so I need a little help.
I write a wrapper for the XMPP lib ASmack.jar
ASmack is a port for Android from Smack.
The code compiles with the "Simple Library Compiler" but when I start the app,
I get the error:
so I tried to make it like in the ReadMe from ASmack with
SmackAndroid.init(context);
but I don't know how to get the context.
Any Ideas?
thanks for help
Björn
here is my code.
I try to program a XMPP Lib.
It's my first Lib, so I need a little help.
I write a wrapper for the XMPP lib ASmack.jar
ASmack is a port for Android from Smack.
The code compiles with the "Simple Library Compiler" but when I start the app,
I get the error:
java.lang.IllegalStateException: No DNS resolver active.
so I tried to make it like in the ReadMe from ASmack with
SmackAndroid.init(context);
but I don't know how to get the context.
Any Ideas?
thanks for help
Björn
here is my code.
B4X:
package anywheresoftware.b4a.objects;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.packet.Message;
import android.content.Context;
import android.app.Application;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
@Version(1.0f)
@Permissions(values={"android.permission.INTERNET"})
@ShortName("chatski")
@ActivityObject
public class chatt {
Connection connection;
Chat chat;
public String ConnectServer(String v) {
connection = new XMPPConnection(v);
????????????????????????????????????????????????????????????????????????????????????
/*Context context=getApplicationContext();
SmackAndroid.init(context);
AndroidConnectionConfiguration mAndroidConnectionConfiguration=new AndroidConnectionConfiguration(v, 5222);
*/
????????????????????????????????????????????????????????????????????????????????????
try{
connection.connect();
}catch(Exception e) {
return e.getMessage();
}
return "connected";
}
public String loginUser(String u,String p){
try{
connection.login(u, p);
}catch(Exception e) {
return e.getMessage();
}
return "login OK";
}
public void ConnectUser(String u) {
chat = connection.getChatManager().createChat(u, new MessageListener() {
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: " + message);
}
});
}
public String sendMessage(String v) {
try{
chat.sendMessage(v);
}catch(Exception e) {
return e.getMessage();
}
return "send!";
}
}
Last edited: