3 回答
TA贡献1898条经验 获得超8个赞
工作示例:
Intent intent = new Intent(ctx, HomeActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder b = new NotificationCompat.Builder(ctx);
b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher)
.setTicker("Hearty365")
.setContentTitle("Default notification")
.setContentText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
.setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND)
.setContentIntent(contentIntent)
.setContentInfo("Info");
NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, b.build());
TA贡献1816条经验 获得超6个赞
我做这种方法,并正常工作。(在android 6.0.1中测试)
public void notifyThis(String title, String message) {
NotificationCompat.Builder b = new NotificationCompat.Builder(this.context);
b.setAutoCancel(true)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.favicon32)
.setTicker("{your tiny message}")
.setContentTitle(title)
.setContentText(message)
.setContentInfo("INFO");
NotificationManager nm = (NotificationManager) this.context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(1, b.build());
}
- 3 回答
- 0 关注
- 805 浏览
添加回答
举报