Android 上的 AlarmManager 不会触发任何东西
我试图让 Android 在用户指定的某个时间触发警报,以检查用户是否已发布到该服务。但是,Android 不会触发该意图。
AndroidManifest.xml:
<receiver
android:name="me.kennydude.dailybooth.NoBoothNotify.AlarmReciever" />
<service
android:name="me.kennydude.dailybooth.NoBoothNotify.AlarmService">
</service>
设置警报的 NoBoothNotify.java 函数:
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);
}
}
如您所见,我正在尝试使其正常工作(因此被注释掉的部分),但是它仍然无法正常工作。
有人可以帮忙吗?
谢谢,
乔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我似乎已经解决了这个问题。由于某种原因,如果接收者是子类,Android 不喜欢触发警报。
为了修复并保持起源,我将其全部移动到一个新的命名空间并且它起作用了。
乔
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