你能不能帮我理解为什么我的警报会被解雇:
我正试图在奥德注册一个未决意图,以便在12:22(现在当前时间)发出警报,但问题是警报不会被触发。我尝试使用硬编码时间替换calendar.getTimeInMilies()中的毫秒:10 000个百万(10秒);
甚至它没有奏效。
AlarmManager alarm_manager =(AlarmManager)this.getSystemService(Context.ALARM_SERVICE);
calendar = Calendar.getInstance();
Intent intent = new Intent(MainActivity.this , AlarmManagerHelper.class);
PendingIntent register =PendingIntent.getActivity(getBaseContext(), 0, intent,0);
calendar.set(Calendar.YEAR,2014);
calendar.set(Calendar.MONTH, 10);
calendar.set(Calendar.DAY_OF_MONTH, 2);
calendar.set(Calendar.HOUR_OF_DAY,12);
calendar.set(Calendar.MINUTE,22);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.AM_PM, Calendar.AM);
alarm_manager.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(), register);
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
Log.d(TAG ,"Time format is :" +formatter.format(calendar.getTime()));
我还在Manifest中设置了以下权限
android:name="android.permission.WAKE_LOCK"
输出:
Time format is :02/11/2014 12:22:00
答案 0 :(得分:1)
尝试使用getBroadcast方法而不是getActivity:
PendingIntent register =PendingIntent.getBroadcast(MainActivity.this, 0, intent,0);
希望这有帮助。