Fetch joined members list from group, xmpp; - android

I'm trying to fetch joined member list from particular group based on room JID, there are couple of method exists, mentioned below:
MultiUserChat.getMembers(); It return XMPPError: forbidden - auth
MultiUserChat.getOccupants(); It return self info only
MultiUserChat.getParticipants(); It returnXMPPError: forbidden - auth
But none of working getting exception XMPPError: forbidden - auth, it seem there is something issue with privacy,which I'm not able to figure out.
Note: JID the name of the room in the form "roomName#service"

As per xmpp documents room/group should be non anonymous to retrieve all members list. So try to set anonymous = false in .yml or configuration file at server side or you can set that also in configuration while creating rooms.
Please not that affiliation should at-least member to retrieve member list

Use this :
multiUserChatManager = MultiUserChatManager.getInstanceFor(XMPPConnection);
MultiUserChat muc =multiUserChatManager.getMultiUserChat("dopee#conference.104.155.155.5");
try {
List<Affiliate> admin=muc.getAdmins();
System.out.println("Admin=====>>>"+admin);
List<String> userlist=muc.getOccupants();
List<Affiliate> member=muc.getMembers();
List<Occupant> memBer=muc.getParticipants();
List<Affiliate> owner=muc.getOwners();
System.out.println("userlist=====>>>"+ userlist.toString());
System.out.println("usercount=====>>>"+ muc.getOccupantsCount());
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}

Related

Update and retrieve chat history in smack with openfire -Android

I am making a chat application with smack library and openfire as a server but everytime i exit the chat conversation activity between two users and come back, the whole chat gets erased. I have already enabled archive settings to store one to one messages in the server but i do not know how to implement it in the app.
I want to show chats history in recyclerview by the sender and the receiver in the recyclerview.
currently i have implemented this function which caused error
private void setChatHistory(String entityBareId) {
EntityBareJid jid = null;
try {
jid = JidCreate.entityBareFrom(entityBareId);
} catch (XmppStringprepException e) {
e.printStackTrace();
}
MamManager manager = MamManager.getInstanceFor(mConnection);
MamManager.MamQueryResult r = null;
try {
try {
r = manager.mostRecentPage(jid, 10);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotLoggedInException e) {
e.printStackTrace();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
}
if (r.forwardedMessages.size() >= 1) //printing first of them
{
Message message = (Message) r.forwardedMessages.get(0).getForwardedStanza();
Log.i("mam", "message received" + message.getBody());
MessagesData data = new MessagesData("send",message.getBody());
mMessagesData.add(data);
mAdapter = new ConversationAdapter(mMessagesData);
recyclerView.setAdapter(mAdapter);
}
}
Error was
Attempt to read from field 'java.util.List org.jivesoftware.smackx.mam.MamManager$MamQueryResult.forwardedMessages' on a null object reference
At r.forwardedmessages.size()>=1.
Thanks in advance
If you want to keep history of conversation, you must save them in database. MAM just for fetching old conversation from server like when you uninstall or logout the app and decide to reinstall and get old messages.
For getting messages from server be sure you already enabled it, then forwarded messages shouldnt be null. here is a guide to enable it.

How to properly resolve conflict during azure synchronization from android?

I'm in trouble with azure synchronization, I'm able to detect the number of pending operations by mCLient.getSyncContext().getPendingOperations(); but can't resolve them. Any help or suggestion?
When working with in an offline scenario and you have pending operations, you can push them to the server by using the push() function.
It would look something like the following:
try {
MobileServiceSyncContext syncContext = mClient.getSyncContext();
syncContext.push().get();
// here you would do a pull on any table you want to grab data from
}
catch (final MobileServiceConflictException e)
{
// the server item causing the exception can be obtained by calling e.getItem()
JsonObject serverObject = e.getItem();
// on the sync context, call one of the following:
// .cancelAndDiscardItem() to cancel update and discard local item
// .cancelAndUpdateItem() to update the local item with the server's copy
// .cancelAndUpdateItem(JsonObject item) to update the server's item w/ the local
// make sure to call push() again on the sync context
}
All in all - make sure you call push() on the MobileServiceSyncContext and then handle any MobileServiceConflictException that may return.
If I catch for MobileServiceConflictException android studio tells me that the Exception is never thrown in this corresponding try block.
try {
MobileServiceSyncContext syncContext = mClient.getSyncContext();
syncContext.push().get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (MobileServiceConflictException e) {
}

smack error when trying to login on server

public void login() {
try {
connection.login(loginUser, passwordUser);
Log.i("LOGIN", "Yey! We're connected to the XMPP server!");
} catch (XMPPException e) {
e.printStackTrace();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
catch (Exception e) {
Log.i("login fuction","login error");
e.printStackTrace();
}
}
[eclipse error log]
I'm getting an error at this stage after successful connection to the server
i don't have the privilege to comment but from the input that you have given here the error possibly lies in the login function that is throwing the null point exception
Possible cases
1) When you call instance method on a null object. you won't get null pointer exception if you call static method or class method on null object because static method doesn't require an instance to call any method.
2) While accessing or changing any variable or field on null object.
3) Throwing null when an Exception is expected to throw.
4) When calling length of array when array is null.
5) Accessing or changing slots of null just like an array.
6) When you try to synchronize on null object or using null inside synchronized block in Java
give the code for login function for further help
Hope this helps you
Which server are you calling? If you are calling gtalk or fchat, those have stopped using xmpp. You may search in Google to find out. And if you plan to connect to you own ip server, please use xmpptc. It would be nice if you could give some more of your code.
I've finally found the solution, i had to add smack-java7 in my dependencies

Android - where can I see the request url that is generated when setDataSource(..) is called?

I am trying to add headers to my setDataSource() method. Is there any way I could see the request itself that is sent ? I need to do this because I'd like to confirm if the url generated by setDataSource method is correctly formed. I don't however see any apis in the MediaPlayer class that can help me do this. Any direction or a solution would be most appreciated.
For non-file media source, the framework handle it by MediaHTTPConnection which is a hide API. You can change its field VERBOSE to true to see the printed log.
Since it's not exported, we can't use it directly. The following code might helpful, but I am not sure if it works. Run it before setDataSource().
try {
Class mediaServiceClass = Class.forName("android.media.MediaHTTPConnection");
Field field = mediaServiceClass.getDeclaredField("VERBOSE");
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.setBoolean(null, true);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
You can refer here to see the detail implementation of MediaHTTPConnection.

How to catch Amazon AWS errors Android

I am constantly getting error reports (from users) such as:
Caused by: Status Code: 400, AWS Service: AmazonSimpleDB, AWS Request ID: c5cb109d-bbff-fcea-bc0d-0cb60ff8f6af, AWS Error Code: RequestExpired, AWS Error Message: Request has expired. Timestamp date is 2012-06-06T13:19:59.415Z. Current date is 2012-06-06T14:20:03Z
Apparently this is because the user has the wrong timezone or something set? Regardless, I would like to catch this particular error and post a message to the user asking them to check their timezone settings however I can't find a way to do it. If I catch AmazonServiceException, the error shows up as null.
How can I catch errors based on Status Code or even Error Code? The current code that I tried looks like this:
try {
dostuff()
} catch (IOException e) {
updateAWS("DownloadErrors");
return "filenotfound";
} catch (AmazonServiceException e) {
return "downloadfail";
}
However AmazonServiceException e is always null so I can't pull any information from it.
other code:
private void doStuff() throws IOException, AmazonServiceException{
//code here
}
Apparently this is what I needed. SDb tracks "RequestExpired" and S3 uses "RequestTimeTooSkewed"
Also, this appears to be occurring because the system time is >15 minutes different than the AWS server. I put a note to the user to check their time and use "Automatic" date/time if possible. Tested it myself and reproduced the error as well as the solution.
try {
result = doOperations();
} catch (AmazonServiceException e) {
if (e.getErrorCode().equals("RequestExpired") || e.getErrorCode().equals("RequestTimeTooSkewed")) {
result = "timestamp";
}
}
return result;
}

Categories

Resources