这是我设置通知的代码,它可以工作:
@Override
public void onReceive(Context context, Intent intent) {
category = (String) intent.getExtras().get("CATEGORY");
notes = (String) intent.getExtras().get("NOTES");
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, MainActivity.class), 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(category).setContentText(notes);
mBuilder.setContentIntent(contentIntent);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
这是来自我的 BroadcastReceiver 的代码片段。每当调用此 BroadcastReceiver 时,它都会在状态栏中显示通知。在调试过程中,我注意到当屏幕关闭并发出新通知时,屏幕不会打开。有没有办法做到这一点?每当发出新通知并且屏幕关闭时,它应该打开一段时间。模拟接收新短信。