Question

I'm trying to alert notifications using phonegap's local Notification Plugin, and it alerts notifications when the application runs, but I don't know how can I configure it to alert plugins on specific times.

Here's the function that does the notification action:

plugins.localNotification.add({ date: new Date(), message: 'Test', id: 123 });

when I tried to put:

date: new Date(12,09,09,2,00,00)

It didn't display any alerts. So, how can I modify it to work with different dates?

Was it helpful?

Solution

I use mobiscroll DatePicker for Android, which returns the datetime in this form:

yyyy-mm-ddThh:mm:ssZ. 

So, it's different from the form the form the plugin uses ... [For how to upgrade the plugin to work with 2.2 check this Question]

So I tried this solution to alert notifications at specific dates:

 if (typeof plugins !== "undefined")
                       {
                        var RId = 0;
                        var rDate =new Date();
                        var RemDate = reminder_deadline.split("T")[0];
                        var RemTimeB = reminder_deadline.split("T")[1];
                        var RemTime = RemTimeB.split("Z")[0];
                        var RYear = RemDate.split("-")[0];
                        var RMonth = RemDate.split("-")[1];
                        var RMonth = RMonth-1;
                        var RDay = RemDate.split("-")[2];
                        var RHour = RemTime.split(":")[0];
                        var RMinute = RemTime.split(":")[1];
                        var RSecond = RemTime.split(":")[2];
                        alert(RYear+".."+RMonth+".."+RDay+".."+RHour+".."+RMinute+".."+RSecond);
                        rDate.setFullYear(RYear);
                        rDate.setMonth(RMonth);
                        rDate.setDate(RDay);
                        rDate.setHours(RHour);
                        rDate.setMinutes(RMinute);
                        rDate.setSeconds(RSecond);
                        plugins.localNotification
                        .add({ 
                            date: rDate,
                            message: reminder_name, 
                            id: RId
                             });
                             }
                             RId++;
             }

Hope it helps :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top