问题
I'm trying to make Android fire a Alarm at a certain time the user specifies to check if the user has posted to the service. However, Android won't fire the intent.
AndroidManifest.xml:
<receiver
android:name="me.kennydude.dailybooth.NoBoothNotify.AlarmReciever" />
<service
android:name="me.kennydude.dailybooth.NoBoothNotify.AlarmService">
</service>
NoBoothNotify.java function that sets the alarm:
public static void settingsChanged(){
Context cntxt = DailyboothApplication.getInstance();
String value = DailyboothShared.getPersonalSetting("noBoothNotify", "no");
AlarmManager alm = (AlarmManager) cntxt.getSystemService(Context.ALARM_SERVICE);
Intent piI = new Intent(cntxt, AlarmReciever.class);
if(Build.VERSION.SDK_INT >= 5){
SharedPreferences prefs = DailyboothShared.getPrefs();
piI.putExtra("account", prefs.getString("current_account", null));
}
PendingIntent pi = PendingIntent.getBroadcast(cntxt, 348347873, piI, PendingIntent.FLAG_UPDATE_CURRENT);
if(value.equals("no")){
alm.cancel(pi);
} else{
String[] values = value.split(":");
Calendar cal = Calendar.getInstance();
Log.d("s", value);
// cal.setTimeInMillis(System.currentTimeMillis());
cal.clear(Calendar.HOUR_OF_DAY);
cal.clear(Calendar.SECOND);
cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(values[0]));
cal.set(Calendar.MINUTE, Integer.parseInt(values[1]));
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
Log.d("s", "setting for " + cal.getTimeInMillis());
Log.d("s", "HRD: " + cal.getTime().toGMTString());
alm.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
/*AlarmManager.INTERVAL_DAY,*/ pi);
}
}
As you can see I'm trying to just get it working one (hence the commented out part), however it doesn't work still.
Can anyone help?
Thanks,
Joe
回答1:
I seem to have fixed this. For some reason Android doesn't like to fire Alarms if the receiver is a subclass.
To fix and keep origination, I moved it all to a new namespace and it worked.
Joe
来源:https://stackoverflow.com/questions/6004237/alarmmanager-on-android-wont-fire-anything