对于自定义提醒应用程序,我正在使用 AlarmManager
并设置弹出PendingIntent
的特定时间。Notification
我有我NotificationManager
的ReceiverActivity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm_receiver);
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)
getSystemService(ns);
Context context = getApplicationContext();
CharSequence ticker = "You have notification";
CharSequence contentTitle = "My Reminder";
CharSequence contentText = "Reminder Content";
Notification notification = new Notification(R.drawable.notif_icon,
ticker, System.currentTimeMillis());
Intent notificationIntent = new Intent(this,
AlarmReceiverActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
}
ReceiverActivity在指定时间弹出,加上通知栏(左上角)的通知,一切正常。但它不是那么用户友好,我只希望通知出现在通知栏中,而在应用关闭时不会弹出任何活动(在现实情况下,可能在您的提醒到期时关闭)