Sinch In-App Instant Messaging - android

Sinch In-App Instant Messaging works perfectly fine with Sinch Managed Push but except this one issue.
This is the sistuation - I receives messages using GCM Listener when my app is foreground or background and I show notification but except in the case when my app is not running.
I inserted debug logs statements to see the flow and it seems that push message arrives in the GCM Listener and gets sent to my service as well but it never gets relayed to the message client listener. This only happens when the app is not running or is closed.
I am doing the following when the app is running background or foreground and I do get callback in onIncomingMessage but same code doesn't work when app is not running.
Sinch Client Initialization Code:
public void startSinchClient(String username) {
try {
sinchClient = Sinch.getSinchClientBuilder().context(this).userId(username).applicationKey(ApplicationConstants.SINCH_SANDBOX_API_KEY)
.applicationSecret(ApplicationConstants.SINCH_SANDBOX_API_SECRET).environmentHost(ApplicationConstants.SINCH_SANDBOX_API_URL).build();
sinchClient.setSupportMessaging(true);
sinchClient.setSupportManagedPush(true);
sinchClient.checkManifest();
sinchClient.addSinchClientListener(this);
if ( messageClientListener == null ) {
messageClientListener = new MyMessageClientListener();
}
sinchClient.getMessageClient().addMessageClientListener(messageClientListener);
Log.e("SinchMessageService", "Login successful.");
} catch (MissingGCMException missingGCM) {
Log.e("SinchMessageService", missingGCM.getMessage());
}
}
OnBind Code
if (!isSinchClientStarted()) {
startSinchClient(currentUserId);
sinchClient.start();
}
In RelayRemotePushNotificationCode:
public NotificationResult relayRemotePushNotificationPayload(Intent intent) {
if ( currentUserId.isEmpty() ) {
Log.e("SinchMessageService", "UserID not available.Please login again.");
return null;
} else if ( !isSinchClientStarted() ) {
startSinchClient(currentUserId);
sinchClient.start();
}
Log.d("SinchService", "relayRemotePushNotificationPayload");
NotificationResult notificationResult = sinchClient.relayRemotePushNotificationPayload(intent);
if (notificationResult.isMessage()) {
sinchClient.startListeningOnActiveConnection();
}
return notificationResult;
}
In MessageClientListener:
public void onIncomingMessage(MessageClient client, final Message message) {
if (message.getRecipientIds().get(0).equals(ApplicationConstants.userInfo.getEmail())) {
sinchClient.stopListeningOnActiveConnection();
....
The above code works in all the scenarios. I mean when the app is running in foreground as well as background. Only when I kill the app never get the onIncomingMessage callback.
Log statements from Sinch Client:
03-03 22:07:44.213 17381-17381/com.ontyme E/SinchClient: mUserAgent.startBroadcastListener()
03-03 22:07:45.271 17381-17381/com.ontyme E/MessageClient: onIncomingMessage: NativeMessage [id=2059913a-27ac-4105-a797-764f09af66d2, nativeAddress=-1321533856]
Anyone else has faced the issue?

Sorry guys there is no problem with the Sinch Managed Push. It was small typo at my end which was causing this issue. My receipentid in the app was not getting initialized correctly when the app was not running which is why all the messages were getting ignored in onIncomingMessage.
Managed Push works seamlessly for me now.

Related

Pusher listener stop after some time

I'm using pusher in my app to get some live values in-app from the server.
I'm subscribing to static channelName but somehow the user can't get data from the server if he keeps the app for a long time open, if the user restarts the app it works fine.
in the pusher dashboard it works well and shows data go to users but, it's not.
when I read on pusher I found that there is ping-pong but, even if I increased pong time it fails too
here is my code:
1- for pusher & channel create ( called in on create ):
options = new PusherOptions();
String APP_CLUSTER = "APP_CLUSTER ";
options.setCluster(APP_CLUSTER);
String APP_KEY = "APP_KEY ";
pusher = new Pusher(APP_KEY, options);
pusher.connect(new ConnectionEventListener() {
#Override
public void onConnectionStateChange(ConnectionStateChange change) {
Log.e("PUSHER SUCCESS => ", change.getCurrentState().name());
}
#Override
public void onError(String message, String code, Exception e) {
Log.e("PUSHER FAILED => ", message);
}
}, ConnectionState.ALL);
2- channel bind & subscribe ( called in onResume ):
channel = pusher.subscribe("xxx");
channel.bind("MessageCreated", event -> {
Log.e("PUSHER DATA => ", event.getData());
});
3- channel un-subscribe ( called in onPause):
pusher.unsubscribe("xxx");
4- disconnect pusher ( called in onDestroy ):
pusher.disconnect();
I hope if anyone can give me the reason for disconnecting for some users, can someone tell me

Listen to notifications using Flutter

I'm a beginner to android app development. I waned to access incoming notifications from my flutter app. I tried https://pub.dev/packages/notifications package. But I can't find how it works.
I also tried to use the NotificationListener but can't figure it out.
Please help if you can.
The notifications package listens to notifications/push messages received by the device. The messages received should be handled inside onData.
Notifications _notifications;
StreamSubscription<NotificationEvent> _subscription;
...
void onData(NotificationEvent event) {
debugPrint('Event received: $event');
}
void startListening() {
_notifications = new Notifications();
try {
_subscription = _notifications!.notificationStream!.listen(onData);
} on NotificationException catch (exception) {
debugPrint(exception);
}
}

AudioDeviceCallback fails when sharedUserId="android.uid.system"

I am developing an app for an Android custom build.
This app needs to subscribe to AudioDeviceCallback in Android's AudioManager.
I'm using:
mAudioManager.registerAudioDeviceCallback(new MyDeviceCallback(), null);
where:
private class MyDeviceCallback extends AudioDeviceCallback {
#Override
public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
Log.d(LOG_TAG, "onAudioDevicesAdded(): New devices detected");
updateAuxStatus();
}
#Override
public void onAudioDevicesRemoved(AudioDeviceInfo[] devices) {
Log.d(LOG_TAG, "onAudioDevicesAdded(): devices removed");
updateAuxStatus();
}
private void updateAuxStatus() {
AudioDeviceInfo[] devices = mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS);
boolean isPluggedIn = false;
for (AudioDeviceInfo device : devices) {
if (device.getType() == AudioDeviceInfo.TYPE_LINE_ANALOG) {
isPluggedIn = true;
}
}
onAuxPluggedInChanged(isPluggedIn);
}
}
This works fine when I run the app with normal user (u0_aXX) but when I run the app as system sharedUser (adding to the Manifest):
android:sharedUserId="android.uid.system"
This callback is being called only after subscribing, but never again. Even when other apps without system user are getting the call normally.
I've traced the call to the AudioManager code and found that postEventFromNative in the AudioPortEventHandler is never being called for my app when it is running as system sharedUser. Since that is a jni call I stopped because I don't fully understand how it works.
What really troubles me is that when running without system sharedUser the same code is working as intended. Is there some restriction to system sharedUser that might be causing this problem?
In the AudioPolicy, registerClient use uid as the key. When the phone booted, system_server or telecom already register notification, if your app run as system user, it will never working.
mNotificationClients.add(uid, notificationClient);

Launching custom chromecast receiver sometimes times out

I have a custom Chromecast receiver that I launch from an Android app when the user selects their Chromecast device from the Cast button. I find that I often get a timeout on the initial connection, but the second time it works fine. Is the issue most likely my web server not responding fast enough, or are there other factors that might cause the timeout?
I'm getting the CastStatusCodes.TIMEOUT in onApplicationConnectionFailed().
My code to launch
(EDITED to include launchApplication)
Builder builder = new GoogleApiClient.Builder(mContext);
builder.addApi(Cast.API, apiOptionsBuilder.build());
builder.addConnectionCallbacks(this);
builder.addOnConnectionFailedListener(this);
mApiClient = builder.build();
if (mApiClient == null) return;
mApiClient.connect();
...
Cast.CastApi.launchApplication(mApiClient, mApplicationId)
.setResultCallback(new ResultCallback<Cast.ApplicationConnectionResult>() {
#Override
public void onResult(ApplicationConnectionResult result) {
if (result.getStatus().isSuccess()) {
onApplicationConnected(
result.getApplicationMetadata(),
result.getApplicationStatus(),
result.getSessionId(),
result.getWasLaunched());
} else {
onApplicationConnectionFailed(result.getStatus().getStatusCode());
}
}
});
The code you have posted is prior to loading the application so if you are getting a timeout in your onApplicationConnectionFailed, then it is further down in your code and not the part that you have posted here. If it is the loading of your application that fails, you need to check on your network and web server, etc.

Android / XMPP: presence listener ignores/drops UNAVAILABLE presences

I'm trying to establish a simple xmpp group chat on Android using the smack/asmack xmpp library. And basically everything is working, except: UNAVAILABLE presences, i.e., when a user leaves a chat room, seem to be ignored. Presences from users entering the group chat are fine.
Both my local Openfire server as well as a xmpp client (Instantbird) tell me that there is a UNAVAILABLE presence when user leaves. Only my stuff has troubles.
Here's the main snippet of my code. In short, when a user (re-)enters the room I see the console output ("presenceListener.processPacket"), when a user leaves nothing happens.
public boolean join(String room, user) {
this.chat = new MultiUserChat(this.xmppConn, room);
this.presenceListener = new PacketListener() {
#Override
public void processPacket(Packet packet) {
System.out.println("presenceListener.processPacket");
if (packet instanceof Presence)
// Handle presence
}
};
this.chat.addParticipantListener(this.presenceListener);
this.messageListener = ...
this.chat.addMessageListener(this.messageListener);
...
try {
this.chat.join(user);
...
} catch (...) {
...
}
}
I would understand when the listener would pick up nothing. But this is too weird for me at the moment. I'm happy about any hint...thanks!
Christian
I found a working solution here.
It uses a PacketFilter with a filter for presence packets, attaching it to the xmpp connection; inspite my solution via attaching a ParticipantListener to the MultiUserChat.
I still don't know why my original attempt fails, but...well...it works now.

Categories

Resources