FLAG_UPDATE_CURRENT无法解析为广播接收器中的变量

时间:2014-08-27 15:13:49

标签: android broadcastreceiver android-pendingintent

我在下面的Android广播接收器代码(最后一行)中收到此错误。我不明白为什么在这种情况下这个常数不可用?

public class OnBootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        // Code to be executed after a phone reboot
        PendingIntent pi;
        AlarmManager am;

        // Read the pending_alarms table and re-create the pending intents
        List<pending_alarm> pending_alarm = new TableControllerPendingAlarm(
                context).read();

        if (pending_alarm.size() > 0) {
            int idx = 0;
            for (pending_alarm obj : pending_alarm) {

                long id = obj.id;
                String mealItemDesc = obj.alarm_desc;
                int alarmMinutes = obj.alarm_minutes;
                int alarmHours = obj.alarm_hours;
                long mealPlanId = obj.id;

                Calendar cal = new GregorianCalendar();
                cal.set(Calendar.DAY_OF_MONTH, obj.alarm_day);
                cal.set(Calendar.MONTH, obj.alarm_month - 1);
                cal.set(Calendar.YEAR, obj.alarm_year);
                cal.set(Calendar.MINUTE, obj.alarm_minutes);
                cal.set(Calendar.HOUR, obj.alarm_hours);

                Intent alarmIntent1 = new Intent(context, AlarmReceiver.class);
                alarmIntent1.putExtra("meal_item_desc", obj.alarm_desc);
                alarmIntent1.putExtra("meal_id", obj.fk_meal_id);
                alarmIntent1.putExtra("pending_alarm_id", obj.fk_meal_plan_id);
                alarmIntent1.setAction(Long.toString(id));
                idx++;
                pi = PendingIntent.getBroadcast(context, idx, alarmIntent1, FLAG_UPDATE_CURRENT);

2 个答案:

答案 0 :(得分:3)

该标志是一个不属于当前类的常量。它是PendingIntent类的一部分。

所以解决它:

PendingIntent.FLAG_UPDATE_CURRENT

答案 1 :(得分:1)

FLAG_UPDATE_CURRENT属于Intent

更改

 pi = PendingIntent.getBroadcast(context, idx, alarmIntent1, FLAG_UPDATE_CURRENT);

pi = PendingIntent.getBroadcast(context, idx, alarmIntent1, Intent.FLAG_UPDATE_CURRENT);