Android 通知无法在给定时间显示

Android 通知无法在给定时间显示,android,notifications,broadcastreceiver,Android,Notifications,Broadcastreceiver,通知无法在给定时间显示。我有字符串格式日期2014-1-10 17:43:00。我将其更改为日历和呼叫通知方法。但它不起作用。请引导我,我需要什么?这是我的密码 它是字符串格式的日期和调用方法 String dtStart = "2014-1-10 17:43:00 "; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date d1 = null; Calendar tdy

通知无法在给定时间显示。我有字符串格式日期2014-1-10 17:43:00。我将其更改为日历和呼叫通知方法。但它不起作用。请引导我,我需要什么?这是我的密码

它是字符串格式的日期和调用方法

String dtStart = "2014-1-10 17:43:00 ";
    SimpleDateFormat  format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    Date d1 = null;
    Calendar tdy1= Calendar.getInstance();

    try {
        d1 = format.parse(dtStart);
    } catch (java.text.ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    tdy1.setTime(d1);
    long startTime = tdy1.getTimeInMillis();
    Log.i("tdy1 milli",startTime+"");

    createScheduleNotificationg(tdy1);
这是通知

public void createScheduleNotificationg(Calendar showCalendar){
    int year = showCalendar.get(Calendar.YEAR);
    int month = showCalendar.get(Calendar.MONTH); // Note: zero based!
    int day = showCalendar.get(Calendar.DAY_OF_MONTH);
    int hour = showCalendar.get(Calendar.HOUR_OF_DAY);
    int minute = showCalendar.get(Calendar.MINUTE);
    int second = showCalendar.get(Calendar.SECOND);

    month+=1;

    AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(getBaseContext().ALARM_SERVICE);
    int id=(int)System.currentTimeMillis();

    Intent intent = new Intent(this,timealarm.class);

    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), id, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    alarmManager.set(AlarmManager.RTC_WAKEUP, showCalendar.getTimeInMillis(), pendingIntent);
}
这是我收到的

public void onReceive(Context context, Intent paramIntent) {
    // TODO Auto-generated method stub
    NotificationManager notificationManager=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.setData(Uri.parse("http://www.papers.ch"));

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

         // Create the notification
         Notification notification = new Notification(R.drawable.ic_launcher, "Visit our homepage", System.currentTimeMillis());
         notification.setLatestEventInfo(context, "Visit our homepage", "http://www.papers.ch",pendingIntent);

         // Fire the notification
         notificationManager.notify(1, notification);
}

请检查这个链接为什么你再次问这个问题-2,因为你已经问了这个问题。您也接受了答案。@Robi Kumar Tomar您给出的答案是正确的,但在我的程序中效果不好。@dipali效果好吗?: