【发布时间】:2011-11-18 13:13:45
【问题描述】:
我一直在研究推送通知,我能够实现它并将其显示在状态栏上,我面临的问题是即使手机被锁定,我也想显示它,在它的锁定屏幕下说(“拖动解锁”),我见过这样的通知,但找不到任何例子。
示例: 就像您接到未接电话一样,它会显示在屏幕上的锁定按钮下方。
代码:
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);
【问题讨论】:
-
不相关的,不一定要全部保存为局部变量
-
目前不可能。
-
@Copa 你是什么意思?你的参考是什么?我有几个应用程序以 OP 描述的方式显示通知(通知栏,屏幕锁定时)。
-
目前无法在锁屏上显示通知、小部件或其他内容。如果您使用的是自定义锁屏,这可以工作 - 但不需要。自定义锁屏是一个普通的应用程序,这就是它起作用的原因。但是android本身的原始锁屏无法更改。我没有官方链接,谷歌告诉你为什么这个dosent工作,但目前没有API来完成这项工作。
-
@Copa:Handcent SMS 设法在锁定屏幕顶部显示一个对话框。我不知道怎么...
标签: android notifications lockscreen