1

我正在制作一个多警报应用程序。我在AlarmMain.class. 但是我不知道为什么 Eclipse 会说:mAlarmSender没有使用局部变量的值。(我用for循环发送很多intent

Intent intent = new Intent(AlarmMain.this,
                    OnBootReceiver.class);

intent.putExtra("hour", pieces[1]);

intent.putExtra("minute", pieces[2]);

PendingIntent mAlarmSender = PendingIntent.getBroadcast(AlarmMain.this, i, intent, 0);

这是代码OnBootReceiver.class

public class OnBootReceiver extends BroadcastReceiver {

private static Intent intent;

static Bundle bundle = intent.getExtras();

static String hour = bundle.getString("hour");

static String minute = bundle.getString("minute");

static Alarm alm;

public static void setAlarm(Context ctxt, Alarm alm) {
    OnBootReceiver.alm = alm;
    AlarmManager mgr = (AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE);
    Calendar cal = Calendar.getInstance();

    cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour));
    cal.set(Calendar.MINUTE, Integer.parseInt(minute));
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    android.util.Log.e("Alarm time!!", "The hour " + hour);
    android.util.Log.e("Alarm time!!", "The minute " + minute);
    if (cal.getTimeInMillis()<System.currentTimeMillis()) {
        cal.add(Calendar.DAY_OF_YEAR, 1);
    }

    android.util.Log.e("***OnBootReceiver", android.text.format.DateFormat.format("MM/dd/yy h:mmaa", cal).toString());

    mgr.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, getPendingIntent(ctxt));
    android.util.Log.e("Alarm time!!", "please help :((");
}

public static void cancelAlarm(Context ctxt) {
    AlarmManager mgr=(AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE);

    mgr.cancel(getPendingIntent(ctxt));
}

private static PendingIntent getPendingIntent(Context ctxt) {
    Intent i=new Intent(ctxt, OnAlarmReceiver.class);

    return(PendingIntent.getBroadcast(ctxt, 0, i, 0));
}

@Override
public void onReceive(Context ctxt, Intent intent) {
    android.util.Log.e("****OnBootReceiver", "got here");    
    Intent i=new Intent(ctxt, AlarmActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ctxt.startActivity(i);
}
4

0 回答 0