I'm trying to create an AIR native extension for sending scheduled notifications, I have the following code:
package com.ane.notification.functions;
public class ScheduledNotificationFunction implements FREFunction {
Context androidActivity;
Context androidContext;
@Override
public FREObject call(FREContext context, FREObject[] args) {
androidActivity = context.getActivity();
androidContext = androidActivity.getApplicationContext();
AlarmManager alarmManager = (AlarmManager) androidContext.getSystemService(Context.ALARM_SERVICE);
int id = (int) System.currentTimeMillis();
Intent intent = new Intent(androidContext, SendNotification.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(androidContext, id, intent, 0);
alarmManager.set(AlarmManager.RTC_WAKEUP, (System.currentTimeMillis()+30000), pendingIntent);
return null;
}
}
Class SendNotification
package com.ane.notification.functions;
public class SendNotification extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Send Notification Code
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ane.notification"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme">
<receiver android:name=".functions.SendNotification"/>
</application>
</manifest>
The problem is that not called SendNotification once marks the definite time to send the notification. I think the ScheduledNotificationFunction code is fine, since I have put in a try / catch and does not generate exceptions, so I assume the alert is register in the system.
I'm not very familiar with programming in android, so anything missing on this wrong or let me know, Thanks.