我正在尝试创建一个用于发送预定通知的 AIR 本机扩展,我有以下代码:
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;
}
}
类发送通知
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>
问题是没有调用 SendNotification 一次标志着发送通知的确定时间。我认为 ScheduledNotificationFunction 代码很好,因为我已经放入了 try / catch 并且不会生成异常,所以我假设警报已在系统中注册。
我对android中的编程不是很熟悉,所以这个错误中缺少任何东西或者让我知道,谢谢。