PushNotifications and MVVMCross - android

I have a service which handles my push notification. When the app is running, everything is fine, but once the app is not running I am getting a null reference exception. I have traced it back to the following line :
newIntent = Mvx.Resolve<IMvxAndroidViewModelRequestTranslator> ().GetIntentFor (request);
This line is used to get the intent for the status bar notification so when the user clicked on it it will take him to the appropriate page inside the app. I am pretty sure that This is null because the application is not running and the MvvmCross framework did not have a chance to initialize and register the IMvxAndroidViewModelRequestTranslator.
My question is what should I use as an alternative?
UPDATE
So I dis some reading and I believe that a regular intent wont work and break my app. I was thinking about creating a dummy activity In my app which will get the regular intent I will send and move on to use the IMvxAndroidViewModelRequestTranslator (which should be not null since the app was started) and create an MvvmCross navigation request.
Any thoughts?
UPDATE 2
Tried the approach above with no luck... still failing on the same line...
So basically the question is how can I launch the app from the status bar while making the MvvmCross eco system start as well...
Thanks
Amit

So what I ended up doing is once the notification arrived and the Mvx.Resolve threw an exception I (meaning the app is not running), I saved the notification data to the app preferences and launched the app to its main activity and there I simpley checked for the notification data and if it existed I navigated to the appropriate activity.

When the Android UI starts, then MvvmCross runs Setup to initialise things like IoC, your application, etc
If you need to initialise your MvvmCross application within a non-UI setting, then try the answer from MvvmCross DataService in an Android Broadcast listener which shows how to access the same setup that the UI uses.

Related

Firebase Dynamic Links does not work if the target app have run

I setup Firebase Dynamic Links in my project. At a glance everything works. But there is one exception. When I click the link my app starts and processes it. But if my app have already run and I click the link the app is appearing on the screen and it doesn't process the link because the intent in the FirebaseDynamicLinks listener is null.
I have only one Activity with singleTask launchMode and I subscribe for the FirebaseDynamicLinks in two places: onCreate() and onNewIntent().
I use the latest version of the library - 19.1.1
Can anybody explain me what I'm doing wrong?
It was my mistake.
In the onNewIntent(Intent) method I used Activity.getIntent() instead of incoming parameter.

Close Android App programatically in Xamarin Forms project

I am using the following code to close the android app in a Xamarin Form project.
var activity = (Activity)Forms.Context;
activity.FinishAndRemoveTask();
It is closing the app but if again I tap on the app it is not opening the new instance of the app as the I can see debugger is still active .
Can anyone help ?
it is not opening the new instance of the app as the I can see debugger is still active
When you use activity.FinishAndRemoveTask() method, this method cant kill your Android app, it just means :
Finishes all activities in this task and removes it from the recent tasks list.
You could use the following code to implement this feature :
FinishAndRemoveTask();
Java.Lang.JavaSystem.Exit(0);// Terminate JVM

Firebase dynamic links handled twice

I have a problem that firebase dynamic link is relaunched when the android app is restarted. The following sequence produces the problem:
click the deep link URL
the app is opened at the view pointed by the deep link (as expected)
close the app (completely)
open the app from the icon
the app is opened at the view pointed by the deep link (even though it should not)
after that it works fine
I am using the latest (9.0.2) libraries. The code is pretty much as in the examples (e.g. here: https://firebase.google.com/docs/dynamic-links/android#add-an-intent-filter-for-deep-links), autoLaunchDeepLink being false.
I noticed that there has been a bug causing this, but it should be fixed in the current release:
https://github.com/googlesamples/google-services/issues/141
I tried a workaround by calling AppInvite.AppInviteApi.getInvitation twice, as instructed in github error report. No success.
In onCreate I am checking that savedInstance is null and checking deep link only if it is.
I am checking deep link also in onNewIntent in order to handle it while the app is running, however this is not called when the problem occurs.
In my manifest, the intent-filter with the specific protocol and host are included only in the main activity. The protocol is used also in other filters in other activities, but I tried also using different protocol in those with no effect. Only the main activity uses AppInvite.AppInviteApi.getInvitation to get the intent. The problem occurs even if I remove other intent filters from all activities.
Any ideas what could be wrong or what I should still check?
You need to call getInvitation() both in your launcher activity, and in the activity which you declared to handle the dynamic link.
But in the activity which handles the dynamic link, you need to pass null instead of passing the activity as second parameter of getInvitation(),
like this AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, null, autoLaunchDeepLink).

Regarding the android app crash

Actually my android app is using quickblox backend, If app got crash somewhere then session gets destroyed but app is not getting closed. it just goes to previous activity, but user is not able to do any operation to backend means service call(saying token required).
So I want a solution that will close my application so that user again restarted the app then session will be regained or we can start the splash activity.
please give me a solution .
I will be grateful , thanks
There is an option to get the app crash data using UncaughtExceptionHandler in your application class.
So , using this you will be notified when your app will crash. but if you want to exit your app , this is not a good solution as suggested by google core team. So you should handle this using try catch and in catch again calling the service to get the token.
First it is not a good use case. Instead of that you can try to catch exception and try to recall your service at runtime.

How to check if certain intent has started

How to check if intent or app has started ?
My use case is I am showing up notifications through my app and I want to clear them all via myBuilder.cancelAll() if default messaging app has started since my app shows sms notifications. So I am kind of looking for something like:
if (smsAppStarted) {
myBuilder.cancelAll();
}
Thanks
To check if an app has started:
Get the package name of the sms app you want to check.
Then refer to my answer here:
Android how to know an app has been started and range apps priority according the starting times
By using that code, the list taskInfo will contain the list of all apps currently running. Search that list using the package name of the sms app. If it is present in that list, it means that that app has started and currently running.
If I get you right, you need to determine, if another app is currently running. If so, then use this solution.

Categories

Resources