通知未在android中显示

时间:2017-04-11 08:10:31

标签: android notifications android-notifications

我正在尝试在用户输入的给定时间显示通知。 这是我设置闹钟的方式。

Intent alarmclass = new Intent(context, notifier.class);
alarmclass.putExtra("Event", data);
alarmclass.putExtra("Items_left", 4);
alarmclass.setAction(data);                                             //To distinguish between alarms for diff event
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, alarmclass, 0);

 Log.d("time set",String.valueOf(myCalendar.getTimeInMillis()));
 notifalm = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
 notifalm.setExact(AlarmManager.RTC_WAKEUP,myCalendar.getTimeInMillis(),al);

负责显示通知的通知程序类。

public class notifier extends WakefulBroadcastReceiver{

@Override
public void onReceive(Context context,Intent intent)
{
    Log.d("notification ", "called");
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.icon)
                    .setContentTitle("Items Left for " + intent.getStringExtra("Event"))
                    .setContentText("Good Luck for " + intent.getStringExtra("Event") + "You forgot to take " + intent.getStringExtra("Items_left") + " items.");
    Intent resultIntent = new Intent(context, showList.class);
    resultIntent.putExtra("Event_Name",intent.getStringExtra("Event"));

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(showList.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =          stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(5, mBuilder.build());
}

}

但通知从未显示过。 请告诉我的错误。

0 个答案:

没有答案