【发布时间】:2014-08-17 00:25:00
【问题描述】:
在 Facebook android 应用程序中,当应用程序被强制关闭时,我们会收到通知。它之所以有效,是因为实现了推送通知。但是我已经在我的应用程序中实现了本地通知,如果应用程序被强制关闭,我希望我的应用程序通知。那么我该如何实现呢。
void showNotify()
{
CharSequence details = "Notification raised";
int reqCode=0;
Intent notificationIntent = new Intent(context,
NotifyListActivity.class);
// notificationIntent.putExtra("clicked", "Notification Clicked");
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP); // To open only one activity
// on launch.
PendingIntent pIntent = PendingIntent.getActivity(context, reqCode,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager nM = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notify = new NotificationCompat.Builder(
context);
notify.setContentIntent(pIntent);
notify.setSmallIcon(R.drawable.appicon);
notify.setContentTitle("");
notify.setContentText(details);
notify.setAutoCancel(true);
nM.notify(reqCode, notify.build());
screenOn(context);
}
【问题讨论】:
标签: android notifications android-notifications android-notification-bar