QuickBlox Attachment issue in Android - android

In group chat I am attaching single file, while sending the QBMessage object has on 1 attachment but on receive that QBMessage object the same attachment comes twice.
This happens only in group chat. In private chat it works properly

Seems like you are using samples from here as a starting point for your application: https://github.com/QuickBlox/quickblox-android-sdk
I had the same bug with it, so my quick solution was override sendMessage method in GroupChatImpl.java
#Override
public void sendMessage(QBChatMessage message) throws XMPPException, SmackException.NotConnectedException {
if (qbChat != null) {
try {
qbChat.sendMessageWithoutJoin(message);
} catch (SmackException.NotConnectedException | IllegalStateException e) {
}
}
}

Related

Parse Android SDK nested saveInBackground not working

I'm working on an existing Android App with parse back-end (localDatastore is enabled but not used in this context) which has the following object structure:
Object A has an array of objects B
Object B has an array of objects C
I save this object structure using saveInBackground in calling the next saveInBackground in the done SaveCallback in reverse Order(C,B,A). For the inner two that works fine, but the top level object isn't saved.
Here's the code (frame, newStep and order are objects of classes inheriting from the ParseObject class)
frame.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.i("Info", "frame.save callback OK");
frames.add(frame);
newStep.setTimeFrames(frames);
newStep.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.i("Info", "newStep.save callback OK");
List<ProcessingStep> steps = order.getProcessingSteps();
steps.add(newStep);
order.setProcessingSteps(steps);
order.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null){
Log.i("Info", "order.save callback OK");
}else{
Log.i("Info", "order.save callback FAIL");
}
}});
} else {
Log.i("Info", "newStep.save callback FAIL");
e.printStackTrace();
}
}
});
} else {
Log.i("Info", "frame.save callback FAIL");
e.printStackTrace();
}
}
});
In the console log I see only "frame.save callback OK", the "newStep.saveInBackground()" seems to be executed too (object appears in backend) however I never get the log message in the callback.
If I save all objects before synchronously without references to each other first and then call the code here, it seems to work (worked at least once) but took for ever (minutes). Queries from the back-end are super fast and the frame object is also saved almost instantly but the done-callbacks seem to bugging. When it fails I do not get any exception, log anything it just seems to fail silently.
I'm looking for any insight why Parse behaves like that as well as how to fix it.
edit: The problem seems to be with the double relation (A to B and B to C). If I try with only A to B or B to C it works just fine. What remains mysterious to me, however, is why splitting the operation up with callbacks doesn't seem to work.
The problem was the enabled localdatastore. Without localdatastore enabled everything works as it should.

Cast custom channel callback never called

I'm working on an Android app that communicates with a Cast receiver app.
Connecting to the app works (I can see the app appear on the tv), but I'm having difficulties getting the custom channel to work.
In the onCreate of my Activity I get the CastContext and add my SessionManagerLister.
mCastContext = CastContext.getSharedInstance(this);
mCastContext.getSessionManager().addSessionManagerListener(getSessionManagerListener(), CastSession.class);
getSessionManagerListener() returns the listener where I register my MessageReceivedCallback:
private SessionManagerListener<CastSession> getSessionManagerListener()
{
return new SessionManagerListener<CastSession>()
{
#Override
public void onSessionStarted(CastSession castSession, String s)
{
try
{
castSession.setMessageReceivedCallbacks("urn:x-cast:be.myappname.player.cast.v1", new Cast.MessageReceivedCallback()
{
#Override
public void onMessageReceived(CastDevice castDevice, String s, String s1)
{
System.out.println("never reaches this callback");
}
});
}
catch (IOException e)
{
e.printStackTrace();
}
}
... other methods omitted ...
}
}
When I tap the Toolbar cast button I can select a device, which triggers the onSessionStarted in the SessionManagerListener (this also starts the receiver app on the tv). I then add the MessageReceivedCallback, but its callback never gets called.
Inspecting my Cast device in Chrome does show the data I'm expecting to receive, it just never seems to reach my Android code.
cast_receiver.js:67 [667.202s] [cast.receiver.IpcChannel] IPC message
[667.202s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:be.myappname.player.cast.v1","senderId":"7c442884-74e6-a388-243c-58b4ab3a4527.3471:com.google.sample.cast.refplayer.tutorial-512","data":"{\"type\":\"login request\"}"}
A colleague is working on the iOS app and that one does receive the callback.
Try the following in onSessionStarted
CastContext cc = CastContext.getSharedInstance(this);
SessionManager sm = cc.getSessionManager();
if (sm != null) {
CastSession cs = sm.getCurrentCastSession();
if (cs != null) {
try {
MyCastChannel mcc = new MyCastChannel();
cs.setMessageReceivedCallbacks("urn:x-cast:be.myappname.player.cast.v1",mcc);
}
catch (IOException e) {
}
}
}
public class MyCastChannel implements Cast.MessageReceivedCallback
{
#Override
public void onMessageReceived(CastDevice castDevice, String namespace, String message)
{
// do your thing
}
}
I had the same problem, this is how I managed to get the message to be sent:
context.sendCustomMessage(namespace, undefined, JSON.stringify({
"a": "b"
}));
This is the javascript on the receiver side. So you need the "undefined" param and also use JSON.stringify(), otherwise the message gets silently dropped.
The undefined means "send to all", but you should probably specify sender-id there.
This is in the v3 API.
In my case, it was more subtle.
The callback worked absolutely fine when the cast session was initiated for the first time. When the user presses the cast button the receiver is registered for the message callback.
override fun onSessionStarted(castSession: CastSession?, p1: String?) {
liveViewModel.requestPause()
castSession?.let {
setCastChannelReceiver(it, this#myActivity)
loadRemoteMedia(it, buildChromeCastInfo())
}
}
fun setCastChannelReceiver(castSession: CastSession?, receiver: CastMessageReceiver) {
castSession?.let {
castChannel.addReceiver(receiver, castSession)
it.setMessageReceivedCallbacks(castChannel.nameSpace, castChannel)
}
}
Although when the user use to kill the Activity which initiated the cast session and then after traversing other parts of app use to again visit the Activity, the callback failed to work.
Remember, when the user visits the Activity for the second time, the CastSession is already connected. As a result the onSessionStarted(castSession: CastSession, p1: String) method is never called.
I was under the assumption that once the receiver has been registered for the session, it need not be registered again. But still for some reason the callback never worked.
As a final resort, just to be assured I re-registered the receiver in the OnCreate() of the Activity.
override fun onCreate(out:Bundle){
....
setCastChannelReceiver(castSession, receiver)
....
}
fun setCastChannelReceiver(castSession: CastSession?, receiver: CastMessageReceiver) {
castSession?.let {
castChannel.addReceiver(receiver, castSession)
it.setMessageReceivedCallbacks(castChannel.nameSpace, castChannel)
}
}
And it worked!!
NOTE: For me, the communication between the Sender(Android App) and Cast Receiver only occurred when the string messages were in JSON format.

Can't able to receive group chat messages using smack-android:4.1.4

I am developing chat app using smack library. I have an issue in group chat. In my app, i am creating a group and in that members are auto-joined.i want to notify all user when I send a message in the group even if they had not initiated a chat.My code is as follow in that I have place listener in init method but unable to receive a message.
multiUserChatManager = MultiUserChatManager.getInstanceFor(mConnection);
mMultiUserChat = multiUserChatManager.getMultiUserChat(to);
mConnection.addAsyncStanzaListener(this, null);
DiscussionHistory history = new DiscussionHistory();
history.setMaxStanzas(0);
mMultiUserChat.addMessageListener(this);
mConnection.addSyncStanzaListener(this, null);
try {
mMultiUserChat.join(from, "", history, SmackConfiguration.getDefaultPacketReplyTimeout());
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
Here is message listener of group
#Override
public void processMessage(Message message) {
Logg.e(TAG,"Message received group..");
}
I don't know why this method does not call when someone send message in group, even I joined group, If I create 1 group and joined 2 users, when 1 user sends message in group then user2 can't able to receive message, but when user 2 send message inside this group then they both are able to receive messages.
Please help me, I can't able to find the solution. Please don't give suggestion which is already deprecated.
Thanks in Advance.!!
I'm full editing answer after full code review. -again-
I suggest to refactor your code to keep separation of roles in more than 1 huge class.
Basically you are especting messages in wrong listener due to many "addasync - addsync" in your code and you are able to receive messages just as side effect of your monster-class-all-in!
I see many optimization you need to apply to your code.
It's too long to explain and out of the question, however, just as example:
1. sendGroupMessage You can check by MultiUserChatManager if you
already joined the chat and then send the message. You must fire a
"join" just once, not everytime you want to send a message.
2. mMultiUserChat.addMessageListener(this);
A listener must be added ONCE or you'll create tons of threads. Probably it works because you have a singleton. While you have a listener, you don't need to add it anymore to that chat if you don't remove it.
mConnection.addSyncStanzaListener(this, null);
Be carefull: you are adding your listener (wich one? You implements tons of listeners with same class) to your connection. Before or later your code will eat an important stanza (prolly a custom IQ) and you'll have an hard to discovery side effects.
mConnection.addAsyncStanzaListener(this, null); same of 3
Check for ProviderManager.addExtensionProvider(), before or later
you'll need some.
Hope that helps.
Try This
step1 : 1 remove this
mConnection.addAsyncStanzaListener(this, null);
mConnection.addSyncStanzaListener(this, null);
Step 2 : add this
private StanzaTypeFilter serverFilter;
private StanzaListener stanzaListener = null;
private XMPPTCPConnection mConnection;
registerStanzaListener(); // where you init connection
public void registerStanzaListener() {
serverFilter = new StanzaTypeFilter(Message.class);
if (stanzaListener != null) {
mConnection.removeAsyncStanzaListener(stanzaListener);
}
stanzaListener = new StanzaListener() {
#Override
public void processPacket(Stanza packet) throws SmackException.NotConnectedException {
processMessage((Message) packet);
}
};
mConnection.addAsyncStanzaListener(stanzaListener, serverFilter);
}
}

Can i catch Volley Debug message programmatically in Android?

Can i catch Volley Debug message programmatically in Android?
For example : D/Volley﹕ [1] Request.finish:...
(From logcat debug log level)
I would like to do something when Volley send this message.
RequestQueue.RequestFinishedListener listener =
new RequestQueue.RequestFinishedListener()
{ #Override public void onRequestFinished(Request request)
{
if(request.equals(yourRequest))
{
// what you want...
}
}
}; requestQueue.addRequestFinishedListener(listener);

Windows Azure Service Client

I'm trying the my Azure Mobile Service. Below is the code to make a new ToDo item entry. The sample Android code shows how to create a mobile client. I added it to the onCreate method as mentioned in the example.
But the insert always fails. I always get an exception which says com.microsoft.windowsazure.mobileservices.MobileServiceException: Error while processing request.
mClient does get initialized. But, mClient.mCurrentUser is null. Not sure if this is a problem.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
mClient = new MobileServiceClient("https://myservice.azure-mobile.net/",
"slkerjasfi234eSomePrivateKey", this);
Item item = new Item();
item.setText("Awesome item");
item.setComplete(false);
mClient.getTable(Item.class).insert(item,
new TableOperationCallback<Item>() {
public void onCompleted(Item entity,
Exception exception,
ServiceFilterResponse response) {
if (exception == null) {
ShowMessage("Success");
} else {
ShowMessage("Failed");
}
}
});
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
In my case, it looked like the key (parameter 2 in MobileServiceClient constructor) was incorrect. That is how I had downloaded it though. It happened again today and I manually fixed the key and it worked for another service. Believe it was the same issue here. To view your key, you go to your service in Azure and click Manage Keys at the bottom.

Categories

Resources