AlarmManager和通知未出现

时间:2016-04-06 17:35:32

标签: android android-studio

不知何故,代码的逻辑似乎是正确的,但是没有通知弹出用户选择的日期/时间。需要一些建议。我正在使用扩展片段的类。每当我设定时间,例如上午8点6分,早上8点15分(现在),我等待,警报不响。我已在我的清单中添加了接收者名称。请帮助!!

int n,i,j;

cout<<"Give the Number N of Stars ";
cin>>n;

for(i=1; i<=n; i++)
{    
    for(j=1;j<=i-1;j++)
        cout<<" ";
     for(j=i;j<=n-i+1;j++)
        cout<<"*";
     cout<<"\n";
}

for(i=1;i<=n;i++)
{    
    for(j=i;j<=n-1;j++)
        cout<<" ";
    for(j=1;j<=2*i-n;j++)
        cout<<"*";
    cout<<"\n";
}

这就是我的AlarmManager的样子

公共类ToDoAlarm扩展了BroadcastReceiver {

 public void oneTime(int day, int month, int year, int min, int hour ){


    int xx= (int) System.currentTimeMillis();
    Calendar cal = Calendar.getInstance();
    Toast.makeText( getContext() ,  "TIME" + xx , Toast.LENGTH_SHORT).show();
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE,min );
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.DATE, day);


    Intent intent = new Intent(getContext(), ToDoAlarm.class);
    PendingIntent examIntent = PendingIntent.getBroadcast(getContext() , xx , intent, 0);
    AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(getContext().ALARM_SERVICE);

    alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), examIntent);


}

}

0 个答案:

没有答案