我一直在處理推送通知,並且能夠實施它並將其顯示在狀態欄上,所面臨的問題是即使手機處於鎖定狀態,也要顯示它在它所說的鎖屏(「拖動解鎖」)下,我看到類似這樣的通知,但無法找到任何示例。Android如何在屏幕上顯示通知
例如: 就像您收到未接來電時,它會顯示在屏幕上的鎖定按鈕下。
代碼:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon_launcher;
CharSequence tickerText = "MyApplication";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.defaults |= Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE|Notification.DEFAULT_LIGHTS;;
CharSequence contentTitle = this.title;
CharSequence contentText = this.message;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(NOTICE_ID, notification);
無關,你不一定需要保存一切,局部變量 – CrackerJack9
這現在是不可能的。 –
@Copa你是什麼意思?你有什麼參考?我有幾個應用程序以OP描述的方式顯示通知(通知欄,屏幕鎖定)。 – CrackerJack9