Android:Service Class中startForeground(id,notification)的id是多少

时间:2016-08-11 08:37:38

标签: android service notifications

Service class中的startForground方法中的id参数是什么。我发现通过google搜索单个Notification的答案。该怎么找到id?任何列表或参考。如果我想显示像facebook这样的多个通知。我如何定义id呢?

notification.flags = Notification.FLAG_NO_CLEAR;
startForeground(1337, notification);

1 个答案:

答案 0 :(得分:2)

简单的notification_id需要改变。

只需为notification_id创建随机数。

    Random random = new Random();
    int m = random.nextInt(9999 - 1000) + 1000;
or
        int m = System.currentTimeMillis()%10000;

并替换此行以添加通知ID的参数以生成随机数

    startForeground(m, notification);