markdowneide
markdowneide
采纳率67.9%
2013-06-14 03:35 阅读 2.0k

如何在status bar中显示通知?

我在 activity 中创建了 notification

Notification n = new Notification.Builder(getApplicationContext())
    .setContentTitle("New mail from " + sender)
    .setContentText(subject)
    .setSmallIcon(R.drawable.notification)
    .build();

现在在status/notification bar 中如何显示通知,并且还带有声音?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    shaojie519 kity 2013-06-14 03:51
    NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    notification.sound = uri; //比如 Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notificationManager.notify(0, notification);
    
    点赞 1 评论 复制链接分享

相关推荐