2
我想让闹钟管理器设置一段时间来更改手机背景,但广播接收器没有做任何事情。你能告诉我为什么吗?Android:我的闹钟管理器广播接收器不工作
调度报警:
public void scheduleAlarm(Context context){
Intent intent = new Intent(context, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 18);
calendar.set(Calendar.MINUTE, 34);
am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
Toast.makeText(context, "Alarm set", Toast.LENGTH_LONG).show();
}
广播接收器:
@Override
public void onReceive(Context context, Intent intent){
PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
GrilledCheeseLookup.getGrilledCheeseJSON(grilledCheeseUrls, context);
Toast.makeText(context, "Alarm worked", Toast.LENGTH_LONG).show();
}
启用清单中:
<receiver android:name=".AlarmReceiver" android:enabled="true" />
你有清单中正确位置的''元素吗?即“”标签之间,但不包含在其他任何内容中,如“”?你确定'name'属性是指向正确的类,在正确的包?假设你使用'Toast'来确定Receiver是否在运行,你确定'onReceive()'中的某些东西在它显示之前没有失败? –
是的,它位于应用程序标签内,但不包含任何其他标签,如。我没有任何软件包中的AlarmReceiver,所以也应该没问题。而且我相信它在展示之前并没有失败。 –
DessertsAndStuff
www.github.com/Akash14204 ..项目学生预算跟踪。我已经使用了它。我可以从那里拿到代码 –