ProcessMessage function is not working in smackapi - xmpp

I am trying to use Smack API to provide chat functionality between my two different projects. Both side I am able to send message. But due to some problem I am not able to receive message on both the side. I think my process-message function is not working properly. How to make it work properly.
My XMPPConnection.DEBUG_ENABLED = true; is working properly, I can see a message is sent and received properly via Google talk. Only I can process the received message..thank you in advance...
public void processMessage(Chat chat, Message message) {
if (message.getType() == Message.Type.chat){
System.out.println(chat.getParticipant() + " says:" + message.getBody());
String cmdmsg = message.getBody();
System.out.println(cmdmsg);
}

Related

Notifications not received on Android device via Azure Notifications hub, but on firebase console they deliver as expected

I have recently updated my app to flutter for cross platform availability but I am having trouble receiving push notifications.
When I send an "alert" to the backend, users should be notified that someone sent out an alert.
Right now when I call the SendFCMNativeNotificationsAsync method, I always get an enqueued response (when I only had an Android version they always said successful).
private async Task sendNotifAsync(Alert alert)
{
Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null;
HttpStatusCode ret = HttpStatusCode.InternalServerError;
var cafe = cafeRepository.GetById(alert.CafeId);
var message = alert.UserName + " needs help in " + cafe.Name;
var notif = "{ \"notification\":{\"title\":\"Somebody needs help\",\"body\":\""+message+"\"},\"data\" : {\"message\":\"" + "From " + alert.UserName + ": " + message + "\"}}";
outcome = await Notifications.Instance.Hub.SendFcmNativeNotificationAsync(notif);
}
This is the code I use to call the notificationhub in my backend.
The weird thing is that when I try to send a test notification via firebase console, it works as expected, so I don't really know where to look right now to fix this issue.
To send push notification to a Flutter application targeting Android and iOS, first we need to handle device registration for the client using the latest and best Installation approach using an ASP.NET Core Web API backend. Check this Registration management document more further details.
There can be many reasons why you are facing this issue, it may be due to Notification Hubs misconfiguration or may be for Application issue due to invalid registration and Push notification service could also be the issues.
Since you are getting notification from firebase console, push notification service should not be an issue. Still you can use the EnableTestSend property while you initialize NotificationHubClient to get a detailed status about push notification service errors that occur if any when the notification is sent.
bool enableTestSend = true;
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(connString, hubName, enableTestSend);
var outcome = await hub.SendWindowsNativeNotificationAsync(toast);
Console.WriteLine(outcome.State);
foreach (RegistrationResult result in outcome.Results)
{
Console.WriteLine(result.ApplicationPlatform + "\n" + result.RegistrationId + "\n" + result.Outcome);
}
I would suggest to read the Diagnose dropped notifications in Azure Notification Hubs document from Microsoft to do some self-diagnosis and solve the problem you are facing. Also read the Send push notifications to Flutter apps using Azure Notification Hubs via a backend service document for more information.

FCM send to specific user

I am using cloud Firestore.
When I use cloud messaging to send push notifications to an app, a message goes to all users (users registered with Authentication) who are registered in the app.
The app has a login function, so I hope only the logged-in user gets notified.
That is, how can I send notifications only to specific users?
I want to set the time and day of the week with cloud messaging and send it to a specific device.
Now I even marked the token on the logcat and tested it in cloud messaging as shown in the picture.
However, the test cannot set the time and day of the week.
Is it possible to do this in the Fire Store? Or do I have to set the time and day of the week in the code as shown in the link?
enter image description here
//FirebaseMessagingService
#Override
public void onNewToken(String token) {
Log.e("NEW_TOKEN", token);
}
//MainActivity
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
#Override
public void onComplete(#NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "getInstanceId failed", task.getException());
return;
}
// Get new Instance ID token
String token = task.getResult().getToken();
// Log and toast
//String msg = getString(R.string.msg_token_fmt, token);
Log.d("NEW_TOKEN", token);
Toast.makeText(MainActivity.this, token, Toast.LENGTH_SHORT).show();
}
});
I'll just write an answer just for better track.
As #Doug already mentioned, you could try using this code sample and try on your own.
Finally, is a good practice to show what you have tried and a code snippet to better understand your question.

How can I approve an XMPP subscription request 'later' in Smack ("Add later" functionality)?

Let us suppose that Alice sends a subscription request to Bob using the next code.
public bool AddBuddy(string jid) {
var roster = conn.Roster;
// 2` param is nickname
roster.CreateEntry(jid, null, null);
roster.SetSubscriptionMode(Roster.SubscriptionMode.Manual);
Presence subscribe = new Presence(Presence.Type.Subscribe);
subscribe.To = jid;
conn.SendPacket(subscribe);
}
When Bob has logged, it receives a popup where tell you if you want to added or not in the next method.
public void ProcessPacket (Packet p0)
{
Presence presence = p0.JavaCast<Presence> ();
var a = presence;
}
But I need to implement a "Add Later" functionality. I have no idea how to save the messages in the server and also how to receive all of them
You can delay the subscription as long as you want, there is no need to save the subscriptions packets on the server. And in order to query the deferred subscriptions requests, simply query the roster for subscriptions not in mode both.
One remark regarding your code: Roster.createEntry(String, String, String[] will automatically send the presence packat. No need to send it again.
No need to save anything on the server as it maintains pending subscribe requests automatically, ie. whenever you login to the server at a later time, the subscribe request will be pushed to you again (if it wasn't dealt with before). Therefore, just save the subscribe request locally in your application in a list or something whenever you receive it from the server, and show that local request list to the user as a "Friend request page" for the user to accept/reject. If your application's lifecycle restarts, it will be receiving all pending subsribe presences again from the server (or whenever it re-logins). Let me know if this works for you.

GWT + Phonegap Cross domain Requests not working

I'm having trouble with making HTTP Requests using GWT 2.4 (and JQueryMobile jquery.mobile-1.0rc1.min.js, but not for anything related with the calls) on Phonegap 1.1.0. What I want to do is to use the POST method on another server in order to receive content and display it.
On the desktop it's working fine (thanks to a reverse proxy configuration). On Phonegap, I read that "the cross-domain security policy does not affect PhoneGap applications. Since the html files are called by webkit with the file:// protocol, the security policy does not apply.". However, it seems that the request is never made on the phone, as the response is empty and the status code 0 - a similar behavior that I experienced before I solved the cross domain issue on the desktop.
I'm using the regular RequestBuilder on GWT to send my requests. Any ideas on why this is happening? All the permissions on Phonegap are active.
edit: Here is my Java code that sends the request, from which I omitted my soap envelope:
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,url);
rb.setHeader("SOAPAction", "assertIdentityWithSimpleAuthentication");
rb.setHeader("Content-type", "application/x-www-form-urlencoded");
String envelope = "etc"; //this is my soap envelope,
try{
rb.sendRequest(envelope, new RequestCallback() {
public void onError(Request request, Throwable exception) {
requestFailed(exception);
}
public void onResponseReceived(Request request, Response response) {
if(response.getStatusCode() == 200){
String aid = Tools.parseMessage(response.getText(),"assertionId"); //this just parses the response in order to get the string I need
Window.alert("Sucess: "+ aid);
sendAssertionID(aid); //and sends it to another function
}
else setError(response);
}
});
}
catch (RequestException ex) {
requestFailed(ex);
}
Check your url. Your code works fine on my android devices, but fails with an invalid url with code 0.
It needs to start with http:// or https://

How to know that when the user goes offline in AgsXMPP?

I am currently trying with agsXMPP library ,
i added users to a treenode on OnPresence event.
its works well, but when the other user goes offline i want to update the tree node,
for that i need his Offline Presence ,How i get result when a chat buddy goes offline ?
When a buddy goes offline you get a OnPresence event with the Type of unavailable.
private void XmppCon_OnPresence(object sender, Presence pres)
{
if (pres.Type == PresenceType.unavailable)
{
// user goes offline
}
}