My problem is i am not been able to receive joined chat rooms. I am using the openfire server 3.8.2 and asmack library asmack-android-16.jar. I receive item-not-found error when i call getJoinedRooms function. though i can see the user is joined in the room from the admin console. Is it the server problem or the client problem or some issue with asmack? Please tell me if someone is able to get joined chat rooms using openfire and asmack for android.
here is how i am call the function:
Iterator RoomsIterator=MultiUserChat.getJoinedRooms(MyService.getConnection(),"user#192.168.1.3");
i also tried this but it gives no response form server:
Iterator RoomsIterator=MultiUserChat.getJoinedRooms(MyService.getConnection(),"user#192.168.1.3/Smack");
Please help me with my problem
Thanks in advance.
I solved my problem by adding a packet listener after call get joined rooms function.. as i was getting an empty list but when i debug i check that the rooms was getting returned in the resultant xml stanze that was sent by the server therefore i run the getjoinedroom function of asmack and then i manually add ha packet listener like this:
public void AddPacketListener(){
PacketFilter filter = new IQTypeFilter(IQ.Type.RESULT);
MyService.getConnection().addPacketListener(new PacketListener()
{
public void processPacket(Packet paramPacket) {
if(paramPacket.getFrom().equals(MyService.getConnection().getUser())){
String xml=paramPacket.toXML();
String from[];
System.out.println(xml);
from=paramPacket.getFrom().split("/");
Pattern pattern = Pattern.compile("<item jid=\"(.*?)/>");
Matcher matcher = pattern.matcher(xml);
String parts[];
Roomlist.clear();
while (matcher.find()) {
parts=matcher.group(1).split("#");
Roomlist.add(parts[0]);
}
return;
}
}
},filter);
}
Related
I am using smack 4.2.0 latest version, here IncomingChatMessageListener is working fine but OutgoingChatMessageListener is not getting called when I send the message. Can any one suggest me whats the issue?
My code is below
ChatManager chatManager = ChatManager.getInstanceFor(mXMPPConn);
EntityBareJid jid = JidCreate.entityBareFrom(mStrJabberID);
Chat chat = chatManager.chatWith(jid);
chatManager.addOutgoingListener(new OutgoingChatMessageListener() {
#Override
public void newOutgoingMessage(EntityBareJid to, Message message, Chat chat)
{
System.out.format("OUTGOING: %s.\n", message);
}
});
chat.send(strMsg);
I traced the code and found out there is a bug in AbstractJidTypeFilter.class in this version.
Changing your version from Smack 4.2.0 to Smack 4.2.2 should work.
Hope it solves your problem.
I am debugging into the source code of smack. You can try the following:
set FromMode.USER to the connection
connection.setFromMode(XMPPConnection.FromMode.USER);
set message type before sending message
message.setType(org.jivesoftware.smack.packet.Message.Type.chat);
Explain:
AbstractJidTypeFilter checks the from jid of message is full or bare. The connection will set the from jid of stanza, default is null. (AbstractXMPPConnection.java#sendStanza, line 666)
MessageTypeFilter will check the type of message is chat or normal.
Parse for Android: Trying to get a device token in Parse but it keeps returning null. This code was working about 6 months back but lately have noticed this issue. Using the device token to subscribe to Parse later on. It just gets stuck in the while loop.I am using Parse 1.7.1 version. Even if I update the parse will this be the right way to get the device token?
private static final String KEY_DEVICE_TOKEN = "deviceToken";
boolean isTokenReady = false;
while (!isTokenReady) {
String deviceToken = (String) ParseInstallation.getCurrentInstallation().get(KEY_DEVICE_TOKEN);
if (!StringHelper.isNullOrEmpty(deviceToken)) {
isTokenReady = true;
} else {
sleep(1000);
}
}
ParsePush.subscribeInBackground("pushtoken_" + deviceToken);
You can use this, if you are retrieving a String:
ParseInstallation.getQuery().get(objectId).getString(KEY_DEVICE_TOKEN)
If you need to get the objectId from the default installation class:
ParseInstallation.getCurrentInstallation().getObjectId();
I'm using version 1.9.2. Hope this helps!
There's been 11 updates of the Android parse sdk. I would definitely update since there's lots of fixes.
Also, you shouldn't have to block your thread to wait for the device token. Did you forgot to save the installation before trying to get the deviceToken?
Like this:
ParseInstallation.getCurrentInstallation().save();
String deviceToken = (String) ParseInstallation.getCurrentInstallation().get( "deviceToken" );
Lastly, Im not sure why you would use a unique device token as push channels. You can use the deviceToken directly. So I would suggest not to subscribe to any channels and push notifications to selected devices using their deviceTokens.
I spent a lot of time on this problem too...
getInstallationId() seems to work. I use installationId to query installations and now it works OK
I am learning to use zeromq polling in android . I am polling on a req socket and a sub socket in the android program(client). So that this client can receive both reply messages from the server and also published messages.
My polling is not working. Both the req socket and the publish socket does not get polled in. If i don't use polling both the sockets receive the message.
I tried searching online but could not find anything relevant.
The client code is this :
public void run()
{
ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket reqsocket = context.socket(ZMQ.REQ);
ZMQ.Socket subsocket =context.socket(ZMQ.SUB);
reqsocket.connect("tcp://10.186.3.174:8081");
subsocket.connect("tcp://10.186.3.174:8083");
subsocket.subscribe("".getBytes());
byte[] receivedmessage;
Poller poller=context.poller();
poller.register(reqsocket,Poller.POLLIN);
poller.register(subsocket,Poller.POLLIN);
reqsocket.send(msg.getBytes(),0);
while(!Thread.currentThread().isInterrupted())
{
if(poller.pollin(0))
{
receivedmessage=s.recv(0);
}
if(poller.pollin(0))
{
receivedmessage=subsocket.recv(0);
}
}
s.close();
context.term();
}
Am i missing out something or doing something wrong?
It looks like there are 3 problems with this.
The main one is you need to call poller.poll() as the first thing inside the while loop. This is why you are not getting any messages.
The next issue is that you're checking the same index for both sockets: I expect the second if statement needs to be
if(poller.pollin(1))
Lastly, the req socket requires a send before every receive, so the call to send needs to be inside the while loop, and before the poller.poll() you just added above :)
By reading asmack source, when create a chat room and invite user to join, the message add a extendsion MUCUser.Invite .
public void invite(Message message, String user, String reason) {
// TODO listen for 404 error code when inviter supplies a non-existent JID
message.setTo(room);
// Create the MUCUser packet that will include the invitation
MUCUser mucUser = new MUCUser();
MUCUser.Invite invite = new MUCUser.Invite();
invite.setTo(user);
invite.setReason(reason);
mucUser.setInvite(invite);
// Add the MUCUser packet that includes the invitation to the message
message.addExtension(mucUser);
connection.sendPacket(message);
}
I use message.getExtension( "x","http://jabber.org/protocol/muc#user"), but it return DefaultPacketExtension, not MUCUser.Invite. So I doubt how i can get inviter name.
Any help will be appreciative!
Using message.getBody(), it can get invite reason and content which contains inviter name. With subString(), I get the inviter name.
But I don't think it is a good solution, my doubt in the question is not solved。
i'm using aSmack (Smack port for Android) to connect to and communicate with an XMPP server (Openfire 3.7.1). i can get multi user chat to work as far as sending messages with the MultiUserChat class. however, calling any method that lists the occupants of the room fails. relevant code:
setDefaultConnection();
if(connection!=null) {
mMuc = new MultiUserChat(connection, "hermitage_recycling#conference.jmartinw7");
try {
mMuc.join("chester");
mMuc.getModerators(); //line 71
ArrayList<Affiliate> dudes = new ArrayList<Affiliate>(mMuc.getMembers());
Iterator<Affiliate> iter = dudes.iterator();
while(iter.hasNext()) {
Affiliate dude = iter.next();
Log.w(this.getClass().getName(), dude.getNick());
}
} catch(XMPPException xmppe) {
Log.w(this.getClass().getName(), "MUC error: "+xmppe.getMessage());
}
}
logcat:
07-10 13:38:56.248: ERROR/AndroidRuntime(13003): FATAL EXCEPTION: main
java.lang.ClassCastException: org.jivesoftware.smack.util.PacketParserUtils$2
at org.jivesoftware.smackx.muc.MultiUserChat.getOccupants(MultiUserChat.java:1797)
at org.jivesoftware.smackx.muc.MultiUserChat.getModerators(MultiUserChat.java:1761)
at org.apache.android.xmpp.XMPPClient$1.onClick(XMPPClient.java:71)
at android.view.View.performClick(View.java:2532)
is there something wrong with the library or am i doing something wrong? getOccupants() seems to work.
MultiUserChat example and javadocs:
http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/
http://www.igniterealtime.org/builds/smack/docs/latest/documentation/extensions/index.html
aSmack:
http://code.google.com/p/asmack/
http://code.google.com/p/asmack/issues/detail?id=72
I believe your problem is being caused by a failure for asmack to load the smack.providers file which tells asmack which classes to load. If you read the README it describes how to load the smack.providers file into asmack(Thanks Flow). You need to do this before starting any XMPP activity.
Try https://github.com/Flowdalic/asmack, as the version you are working off has not been updated in 2 years.
Please read the README of aSmack and follow the instructions about the ProviderManager.