java signalr don't receive message when app is closed - android

I'm using SignalR. I can receive Messages and show Notification when the app is open or is in the background. but when closed application I can't receive messages. Does anyone have a solution to this?
I have the following code in MainActivity OnCreate:
ActivityChat.connection.received(json -> runOnUiThread(new Runnable() {
#RequiresApi(api = Build.VERSION_CODES.O)
public void run() {
JsonObject jsonObject = json.getAsJsonObject();
if (jsonObject != null && jsonObject.has("A")) {
jsonArray = jsonObject.getAsJsonArray("A");
String method = jsonObject.get("M").getAsString();
//PushNotifications(method,jsonArray);
if (method.equals("addNewMessage")) {
if (jsonArray != null && jsonArray.size() != 0) {
if (jsonArray.get(2).getAsString().equals(driverID)) {
if (TransportClass.showCaseView != null && !TransportClass.showCaseView.isShowing()) {
Notificate();
}
}
}
}
}
}
}));

This is by design, but not by the design of the SignalR client itself; this is a design consideration when building a mobile app on either native iOS or Android. When the app isn't in focus, the app isn't in the background running, either. AFAIK, in most cases the app is only running when you have it open on the phone. This is when the SignalR connection would be active - the moment you close the app, you also close the connection.
You'd want to use something like notifications here to tell the user to open the app, then when they do, the real-time connection would be there again.

Related

Android "A Call is in Progress" notification issue

I created a chat application that uses Twilio Sdk. Everything works fine but after a Video Call ends, I get this notification which doesn't go away whatever I try to do. After this notification appears, if I try to initiate Video Call, it doesn't work then. Maybe its using some of my resources like microphone which does not allow the app to start Video Calling because the Android system shows that microphone is still being used. Also this is appearing on my Redmi 9C. I have already searched everywhere on the net but no such solution found. It also states its a bug in some devices but there must be something that can be done to resolve this. Help would be appreciated thank you.
This is the code that is used to disconnect from a room:
private fun killAllVideoProcess() {
if (localVideoTrack != null) {
if (localParticipant != null) {
localParticipant!!.unpublishTrack(localVideoTrack!!)
}
localVideoTrack!!.release()
localVideoTrack = null
}
if (room != null && room!!.state != Room.State.DISCONNECTED) {
room!!.disconnect()
disconnectedFromOnDestroy = true
}
if (localAudioTrack != null) {
localAudioTrack!!.release()
localAudioTrack = null
}
if (localVideoTrack != null) {
localVideoTrack!!.release()
localVideoTrack = null
}
}//killAllVideoProcess ends

Android Azure Offline Sync - Not completing sync

I have an android app with Azure Mobile Services and implemented Offline Sync. The app works well but when syncing data it seems not to complete so there is always a few rows on tables which have not synced?
Anyone have any ideas what the problem might be. I believe that on the next try it would finish where it left off or am I wrong?
Thanks in advance
The app works well but when syncing data it seems not to complete so there is always a few rows on tables which have not synced?
I would recommend you use fiddler to capture the network traces when handling the sync operations.
For Incremental Sync, the request would be as follows:
Get https://{your-app-name}.azurewebsites.net/tables/TodoItem?$filter=(updatedAt%20ge%20datetimeoffset'2017-11-03T06%3A56%3A44.4590000%2B00%3A00')&$orderby=updatedAt&$skip=0&$top=50&__includeDeleted=true
For opting out of incremental sync, you would retrieve all records without the filter updatedAt.
Get https://{your-app-name}.azurewebsites.net/tables/TodoItem?$skip=0&$top=50&__includeDeleted=true
Note: If there are too many items, the SDK would send multiple requests to pull all items that match your given query from the associated remote table. Also, you need to make sure you specify the includeDeleted() in your query.
In summary, you need to make sure that all items could be retrieved via the above requests. Additionally, if the pull operation has pending local updates, then the pull operation would first execute a push operation. So, I assume that you could catch the exception when calling pull operation for handling the conflict resolution.
Bruce's answer is fine but I used a slightly different method without the need to use fiddler.
I change my connection from this
mClient = new MobileServiceClient("[AZUREWEBSITE]", cntxall);
mClient.setAndroidHttpClientFactory(new MyOkHttpClientFactory());
To this
mClient = new MobileServiceClient("[AZUREWEBSITE]", cntxall).withFilter(
new ServiceFilter() {
#Override
public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilter) {
// Get the request contents
String url = request.getUrl();
String content = request.getContent();
if (url != null) {
Log.d("Request URL:", url);
}
if (content != null) {
Log.d("Request Content:", content);
}
// Execute the next service filter in the chain
ListenableFuture<ServiceFilterResponse> responseFuture = nextServiceFilter.onNext(request);
Futures.addCallback(responseFuture, new FutureCallback<ServiceFilterResponse>() {
#Override
public void onFailure(Throwable e) {
Log.d("Exception:", e.getMessage());
}
#Override
public void onSuccess(ServiceFilterResponse response) {
if (response != null && response.getContent() != null) {
Log.d("Response Content:", response.getContent());
}
}
});
return responseFuture;
}
}
);
This is the logging method for Azure connections and shows the request in the log.

How to scroll an accessibilitynodeinfo?

I am building an accessiblity service for 3-party application using AccessibilityService API. But I don't know how to scroll an accessibilitynodeinfo backward? Can you guys help me out?
node.perform(AccessibilityNodeInfo.ACTION_SCROLL_BACKSCROLL) didn't work.
I believe this is what you want:
void scrollBackward(AccessibilityNodeInfo) throws NotScrollable {
while (node != null) {
if (node.isScrollable()) {
node.performAction(ACTION_SCROLL_BACKWARD);
return;
}
node = node.getParent();
}
throw new NotScrollable("This node cannot be scrolled");
}
Note: I'm on my phone typing this up, so forgive me if this doesn't quite compile. It should be very close.

Sinch In-App Instant Messaging

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.

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.

Categories

Resources