这是我设置通知的代码,它有效:
@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 时,它都会在状态栏中显示一条通知。在调试过程中,我注意到当屏幕关闭并发出新通知时,屏幕不会打开。有什么办法可以做到这一点吗?每当发出新通知并且屏幕关闭时,它都应该打开一段时间。模拟就像收到一条新短信。
尝试这个:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
wl.acquire(3000);
wl.release();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)