Titanium: AlarmMananger Module and Cancelling Notifications - android

I am currently using version 0.11 of the AlarmManager module for my Titanium app (currently built with version 3.2.2 of the SDK). I am noticing some odd behavior when cancelling alarms, specifically when cancelling a notification after resuming the app. Here is the case:
In some cases, when the app is put into the background, a reminder notification may be set for a configurable amount of time in the future. If the user resumes the app before this notification fires, the app should cancel the pending notification, as the user doesn't need it. However, the notification is not being cancelled. Now, I see in the log that the module is attempting to cancel the notification (using the correct request code for the notification), and no error is thrown by either my app or the module, but, again, the notification is not cancelled.
In testing, if I create a notification via the module in the app, and cancel that notification without pausing the app, that notification is cancelled correctly.
I suspect this has something to do with a context switch when the app resumes (since the module relies on the app's current context when spinning up the notification service), but I'm not sure why this occurring.

The issue actually had to do with the type of the request code being sent to the alarm module's cancel function. If the type of the request code variable is not a number (as in java.lang.Number), the module uses a default request code, which would not match the code of the previously scheduled alarm.

Related

Plot Projects - exit geofence occasionally not triggering

I'm using Plot Projects service to send geofencing notifications to users of iOS and Android application.
There seems to be a strange situation occasionally happening, that the notification linked to exit event on geofence does not get triggered. User enters the geofence, gets the enter notification (which is obviously a different notification than the exit one, but on the same geofence and with the same configuration except for the trigger and custom data), but after leaving the geofence the exit notification does not get triggered.
I'm using Notification filter, so that the application, when receiving the "silent" notification, contacts the back-end (by making an API call), and depending on the response it shows the notification or ignores it.
Although the app logs are not accessible at the time when this happens, what can be deducted from the back-end logs is that the call has never reached the back-end API. This would mean that the "silent" notification has either never been triggered (meaning that the geofence exit was not recorded by Plot Projects SDK for some reason), or it has been triggered but for some reason not handled properly by the app. Having in mind that I do get proper exit notifications occasionally, I'm not sure an in-app problem could be causing this.
Looking at the Plot Projects dashboard, I see that enter notification has been triggered once, while the exit has not been triggered at all. This is on Notifications screen, under Sent column.
As noted, the only difference between configuration of enter and exit notifications is the Notification trigger setting (On entering as opposed to On exiting), and the custom data which is as follows:
{ "geofenceId" : "{geofenceid}", "action" : "enter" }
{ "geofenceId" : "{geofenceid}", "action" : "exit" }
Both notification also use segmentation, with the segmentation configuration being the same.
So, several questions here:
Has anyone encoutered a similar problem, and what has been the cause/solution?
When using notification filter, will the column "Sent" show the number of notifications that were shown to the user, or will it include count of "silent" notifications? (this may help deducting what the issue is)
Is there a reason in general why an exit notification may not trigger, depending on some specific conditions regarding the enter notification or other parameters? For example, 3G connection issue, network issue, etc.
The latest version (1.15.0) has improved on this making enters and exits more consistent. I would recommend using that version when testing exit notifications.
Because of limitations related to efficiency and platform there will always be a small difference between the number of sent enter notifications and the number of exit notifications.
When notifications are filtered out using the notification filter they aren't included in the notification statistics. For silent notifications geotriggers may be more suitable, as those can be used silently while still showing up in the statistics.
Various reasons could prevent notifications from being sent, for example when the device is no longer able to determine its location.

ngCordova LocalNotification plugin

I'm using the ngCordova LocalNotification plugin in my Ionic app and I am trying to get it to repeat but with a random time span.
For example the user will trigger the notification to launch in 1 minute, and after that I would need to have the notification launched again in another 2 minutes (hypothetical example, in real life scenario the time span would be much higher, ie a couple days).
So far I can get the notification to execute for the first time.
Then, I am using the $cordovaLocalNotification:trigger method to detect when the notification was triggered and inside of that method I have a code to schedule a new notification.
All of this works, but in order to launch whatever it is inside of that method's body, I have to acknowledge the notification on my device and click on it, then it launches this method.
So I am wondering if there's a way to have it schedule a new notification without me having to open the previous notification?
All of this has to happen locally on the device and the notification should persist even if the device is rebooted. Thanks a lot!
When the application go in backround, the webview stops the javascript execution. When you click on the notification, the app became a foreground process and javascript continue the execution.
So it seems that it works only when you click on the notification (that open the app) because only when the app is opened, the js code is executed.
You could double check this if you don't click on the notification, opening the app after the notification is displayed (without clicking it).
To clear all the triggered notification you could use the getTriggeredIds(scope) method to get all triggered notification IDs and the clear(ids, scope) method to clear them.
See the localNotification plugin documentation for more information.

How to send local notification android when app is closed?

I'd like to know if it's possible to send a local notification to the device when the app have been opened then closed.
It works already when my app is opened and when it's in the background.
Thanks
Edit : I think i wasn't clear enough:
I want to send a local notification at a given time even if the app is not running at that time.
By "Local Notification" i mean a Notification (android class) created in my app and send by using an AlarmManager and a BroadcastReceiver.
closed -> killed the process of my app
Most means of "killed the process of [your] app" will leave your alarms intact, and so whatever you have scheduled will remain scheduled and keep being invoked as you set up.
I want to send a local notification at a given time even if the app is not running at that time.
Again, AlarmManager is not dependent upon your process being around, so long as it can invoke the PendingIntent that you supply. So long as the BroadcastReceiver you are using is registered in the manifest (and not via registerReceiver()), it should work fine.
If the user force-stops your app -- usually via the Settings app -- then not only will your alarms not be invoked, but your code will never run again, until something explicitly starts up your app (usually the user tapping on your icon in the launcher). There is nothing that you can do about this.
it's hard to explain things when you do understand fully and when english is not your native language
There are many Android developer support sites, offering a variety of languages.
you need to create a service, http://developer.android.com/guide/components/services.html

ios alarm functionality limited?

I have an app which is on Android and iOS. I have added a local notification to fire every 24 hours at a time specified by the user of the app. In Android, the local notification functionality is exactly what I need, but in iOS it seems to lack the functionality I need, unless maybe I am missing something...
Lets say the user sets the time the notification is to fire to 11:00am. In Android, at 11AM, it will wake up the app, go to the broadcase receiver and I am able to run code in a method that calls out to an API to fetch the latest data. Once it gets the data, it posts the notification to the user.
In iOS, it seems the data being posted to the user has to be pre-scheduled. So I have to create the notification message during scheduling of the notification. What I need is to be able to do something more like the above example.
So the problem is that at the time of when the notification is scheduled to fire, I need to check for fresh data, not the day before...
Any suggestions?
The same functionality doesn't exactly exist on iOS.
You can setup a local notifications using the functionality of a UILocalNotification object. With this you can set fireDate, etc. which is sort of like a push notification without a server. You can send a message, add a badge on the app icon, play a sound, etc.
Now the issue is that the app doesn't get launched by the OS. The app simply registers a notification in the OS, which is then handled at the fireDate time. This means you won't be able to have a chance to check for data and verify whether to continue with the notification, etc.
UILocalNotification Class Reference

Notifications on an app after it is shut down with the 4.0 android task manager?

I'm using C2DM in my application, and I have a receiver, which sends data to a class in the application. The class creates a notification and notifies the notification manager to post it.
The problem is that this does not work when the app is forced close manually through the settings, as this also (apparently) shuts off the broadcast receiver.
What I get though is that when an app is shut off with android 4.0's new task manager (the one thats similar to 3.0 but a user can also swipe an app to the left or right to shut it off) it behaves differently: the broadcast receiver is still working, as I get the intent from the C2DM message, but for some reason my phone still plays the notification noise, whilst no notification appears in the tray.
I can't figure out what's happening, because there is no way for the sound to play without the notification to appear, as the sound is attached to the notification and plays when it's posted, no other way. But no notification appears.
Any insight on why this might be happening would be awesome, or what the new 4.0 task manager actually does to apps when you swipe them off the list.
Thanks.
Figured it out, the broadcast receiver was still responding but just failing because it was retrieving things from a class that was part of the main app and was now dead, so now the things it needs are stored in sharedprefs, and retrieved before the notification gets sent.
So to answer the question, no swiping an app from the task manager in 4.0 does not "force kill" the app in the same was as the force kill button in the applications menu in settings. It does kill off the app in such that next time you open it, all the activities restart from scratch, just like if you had been in the last remaining activity and pressed back, hereby calling finish() on the last alive task and shutting down the app. broadcast revivers (and services i assume) still are running afterwards.

Categories

Resources