Android xmpp MUC setting default configuration - android

Am using the Xabber open source project and am able to create a new group, But it always says: This room is locked from entry until configuration is confirmed. I tried to set a default configuration but it throws me exception: 401 not authorized. Whats exactly the problem.
final MultiUserChat multiUserChat;
try {
multiUserChat = new MultiUserChat(xmppConnection, room);
// CHANAKYA: set default config for the MUC
// Send an empty room configuration form which indicates that we want
// an instant room
try {
multiUserChat.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
} catch (XMPPException e) {
e.printStackTrace();
}

I was also facing the same error. Here I modified the code and it's work for me.
Error 401 is not authorized error when we are calling the any getConfigurationForm(), without joining it.
multiUserChat.join(nickname, password);
setConfig(multiUserChat); // Here I am calling submit form
private void setConfig(MultiUserChat multiUserChat) {
try {
Form form = multiUserChat.getConfigurationForm();
Form submitForm = form.createAnswerForm();
for (Iterator<FormField> fields = submitForm.getFields(); fields
.hasNext();) {
FormField field = (FormField) fields.next();
if (!FormField.Type.hidden.equals(field.getType())
&& field.getVariable() != null) {
submitForm.setDefaultAnswer(field.getVariable());
}
}
submitForm.setAnswer("muc#roomconfig_publicroom", true);
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
multiUserChat.sendConfigurationForm(submitForm);
} catch (Exception e) {
e.printStackTrace();
}
}
And now I am able to successfully submit the form without any exception. Hope this will work for you.

You must have permissions to set the configuration. This can usually be changed in the server settings. If you have Openfire for example you should go to Group Chat>Group chat settings>Click your Group Chat service>Room Creation Permissions or Administrators.
You are probably unable to change this client side, it's only possible if you have access to the server you are trying to connect to.

Related

XMPP - Using lib Smack remove user from group(conference) in MUC

We are integrating MUC in our app for group chat. where we can create group(conference) and adding members. Questions are-
Removed member still getting group messages. What is proper way of remove a member from group?
How to get total members of group (online/offline)?
We are using following methods to remove a members-
public void kickOutRoomMember(String groupJid, String memberNickName) {
MultiUserChat muc;
try {
if (manager == null) {
manager = MultiUserChatManager.getInstanceFor(connection);
}
muc = manager.getMultiUserChat(groupJid);
muc.kickParticipant(memberNickName, "");
} catch (Exception e) {
e.printStackTrace();
}
}
public void removeOutRoomMember(String groupJid, String memberNickName) {
MultiUserChat muc;
try {
if (manager == null) {
manager = MultiUserChatManager.getInstanceFor(connection);
}
muc = manager.getMultiUserChat(groupJid);
muc.banUser(memberNickName, "");
} catch (Exception e) {
e.printStackTrace();
}
}
Theorically you are right.
Just check
If user who invokes banUser has grants to do it
to pass bare
jid and not memberNickName as first parameter in method.
javadoc
muc.banUser("Mickey Mouse", ""); //does not works
muc.banUser("mickeymouse#server","") // will works
Install "Rest API" plugin.
Rest API plugin provides all the API related group. Create Or delete a group, Add or remove a member from a group, get all members of group etc..

Invitation Listener not working smack 4.2

I can create group chat room successfully XMPP(smack). I have added
invitation listener, but never called. Does anyone know how to do it?
Using:
XMPP
Smack 4.2
Openfire server
Send Invitation code:
muc.invite(userId +"#" +XMPP.getInstance().HOST + "/Smack", "Meet me in this excellent room");
Invitation listener code:
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
manager.addInvitationListener(new InvitationListener() {
#Override
public void invitationReceived(XMPPConnection xmppConnection, MultiUserChat muc, String inviter, String reason, String password, Message message) {
try {
muc.join(nickname);
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
}
});
Probably you have an issue about RESOURCE.
When you send an invitation to a certain JID, you might omit resource part or the message will be sent only to specified resource.
JID it's composed in following way:
user#serverdomain/resource
With this invitation, you are inviting only user using "Smack" as Resource.
Resource it's configurated in AbstractXMPPConnection object or in login phase
XMPPTCPConnectionConfiguration.builder()
.setServiceName(serverName)
.setHost(server)
.setPort(port)
.setResource( RESOURCE_IDENTIFIER)
.build();
connection = new XMPPTCPConnection(config);
connection.login(username, password, RESOURCE_IDENTIFIER);
So, probably, you declared as your resource identificator (just an arbitrary String) not "Smack" but "Spark" o something else or left default one.
Just omit Resource part (or fix with correct one, but I suggest to omit)
muc.invite(userId +"#" +XMPP.getInstance().HOST, "Meet me in this excellent room");
Of course, userId must exist and HOST it's the valid one

Android ADD FRIEND using Smack

I am new to the use of smack library and making one chatting application. I have made upto much extent and at this step i want to ask two questions.
when i add a friend the friend got added in my list but there is not any notification sent to the FRIEND whom i have added, How to achieve the same. I have added the code below.
The second thing i want to ask is that how can I check whether the user which I am going to add is a part or member of the app or not ( mean it is on the server or not). So that the user who is not registered to the app should not be added in the friends list.
here is the code
public static boolean addFriend(String jid) {
String nickname = null;
nickname = StringUtils.parseBareAddress(jid);
RosterEntry entry4 = roster.getEntry("samsad");
if (!roster.contains(jid)) {
try {
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo(jid);
connection.sendPacket(subscribe);
roster.createEntry(jid, nickname, null);
// Send a roster entry (any) to user2
RosterExchangeManager REM = new RosterExchangeManager(connection);
REM.send(entry4, jid);
return true;
} catch (XMPPException e) {
System.err.println("Error in adding friend");
return false;
}
} else {
return false;
}
}
Roster Exchange manager running in the service in background
/**Remotr Exchange Manager*/
RosterExchangeManager rem = new RosterExchangeManager(connection);
// Create a RosterExchangeListener that will iterate over the received roster entries
RosterExchangeListener rosterExchangeListener = new RosterExchangeListener() {
public void entriesReceived(String from, Iterator remoteRosterEntries) {
notification("Receive==4");
while (remoteRosterEntries.hasNext()) {
try {
// Get the received entry
RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) remoteRosterEntries.next();
// Display the remote entry on the console
System.out.println(remoteRosterEntry);
// Add the entry to the user2's roster
roster.createEntry(
remoteRosterEntry.getUser(),
remoteRosterEntry.getName(),
remoteRosterEntry.getGroupArrayNames());
notification("Receive==1");
}
catch (XMPPException e) {
e.printStackTrace();
}
}
}
};
rem.addRosterListener(rosterExchangeListener);
}
else{
showToast("Connection lost-",0);
}
}
1, The problem is you must register a PacketListener for Presence.Type.subscribe before you connect to server. All the process of add and accept friend i answered in here
2, You can use UserSearch class to search for a specific user and if user is not found on server then you can assume that user is not registered on server.

Group chat in gtalk for Android

I am making gtalk Im using smack 3.2.1 API.
I am stuck with group chat implementation.
here is my code for initiate a group chat:
conf = new MultiUserChat(connection, "room#groupchat.google.com"); // create object of multiserchat class
try
{ // Create the room
conf.create("room#groupchat.google.com");
// Send an empty room configuration form which indicates that we want an instant room
conf.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
}
catch (XMPPException e)
{
Toast.makeText(this, "Error in create room: "+e.toString(), Toast.LENGTH_LONG).show();
}
conf.invite("userid", "Invitation for group chat");
But I am getting error: Service not Available (503)
Thanks in advance.
Room should be -- private-chat-
And there is no need to create room.
Simply join the room with users name and password. That will satishfy:
Code snippet:
String room = "private-chat-" + UUID.randomUUID().toString();
room = room + "#groupchat.google.com";
MultiUserChat muc = new MultiUserChat(cc, room);
muc.join("username", "password");
muc.invite("username", "hi");
Let me know if this works.

Android OpenErp Search Request XMLRPC

I am working on an android application which is able to connect with an openerp server and retrive the userid and also the individual fields of the different contacts of that user.
below is the code on the things i have done so far
public int Search()
{
searchClient = new XMLRPCClient("http://"+lp.HOST+":"+lp.IN_PORT+lp.URL_XML+lp.URL_OBJECT);
try
{
record = (Array[]) searchClient.call("search",lp.DB_NAME, lp.uid1, lp.PASSWORD, "res.partnet.contact","execute", arguments);
}
catch(Exception e)
{
Log.i("------------------ CONNECTION FAILED Search", e.toString());
}
return 0;
}
i appreciate the help given
Thank you,
try to interchange the position of method search and execute.The method execute must be given before search.Also try searchClient.callEx instead call only like you do it above!
record = (Array[]) searchClient.callEx("execute",lp.DB_NAME, lp.uid1, lp.PASSWORD, "res.partnet.contact","search", arguments);

Categories

Resources