如何在Notify manager(Android)上创建动态ID?
我制作的Android应用程序有问题。我有两个按钮,按下后都会发出通知,但问题出在这里。两者都有一个不变的ID(1和2) 这意味着通知1始终显示在状态栏的第一个位置。当您先按notification2时没有区别,它总是先按notification1,然后按notification2。现在我需要知道如何制作动态ID 有谁能告诉我一个解决办法,我如何才能避免不变的秩序 以下是完整的代码:如何在Notify manager(Android)上创建动态ID?,android,dynamic,notifications,Android,Dynamic,Notifications,我制作的Android应用程序有问题。我有两个按钮,按下后都会发出通知,但问题出在这里。两者都有一个不变的ID(1和2) 这意味着通知1始终显示在状态栏的第一个位置。当您先按notification2时没有区别,它总是先按notification1,然后按notification2。现在我需要知道如何制作动态ID 有谁能告诉我一个解决办法,我如何才能避免不变的秩序 以下是完整的代码: public void sendNotification(View view) { switch(v
public void sendNotification(View view) {
switch(view.getId()){
case R.id.button1:
Notification1();
break;
case R.id.button2:
Notification2();
break;
}
}
private void Notification1() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setAutoCancel(true);
builder.setContentTitle("BasicNotification");
builder.setContentText("Test");
builder.setSmallIcon(R.drawable.icon1);
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
manager.notify(1, notification);
}
private void Notification2() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setAutoCancel(true);
builder.setContentTitle("BasicNotification");
builder.setContentText("Test");
builder.setSmallIcon(R.drawable.icon2);
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
manager.notify(2, notification);
}
System.currentTimeInMillis()
是我生成唯一ID的首选方法
manager.notify(System.currentTimeInMillis(), notification);
System.currentTimeInMillis()
是我生成唯一ID的首选方法
manager.notify(System.currentTimeInMillis(), notification);
System.currentTimeInMillis()
是我生成唯一ID的首选方法
manager.notify(System.currentTimeInMillis(), notification);
System.currentTimeInMillis()
是我生成唯一ID的首选方法
manager.notify(System.currentTimeInMillis(), notification);
现在您可以在代码中这样使用它
manager.notify(uniqueID , notification);
现在您可以在代码中这样使用它
manager.notify(uniqueID , notification);
现在您可以在代码中这样使用它
manager.notify(uniqueID , notification);
现在您可以在代码中这样使用它
manager.notify(uniqueID , notification);
谢谢你的快速回复!但是除了这个我还得去哪里?对不起,我真的没什么事了:(感谢老兄!!!天哪,你是最棒的:D我在一个德国论坛上寻求帮助,但awnser需要几天的时间,然后它就不起作用了,现在我在一个英语论坛上,2分钟后我得到了一个简短而称职的awnser:D再次感谢你帮我从谷歌搜索中解脱出来^^^注意,虽然这可能有效,但生成的值可能出乎意料。
System.currentTimeMillis()
返回一个long
值,该值大于整数.MAX\u值
,因此向下转换需要将该值包装成整数。感谢您的快速回答!但是我必须在哪里执行此操作?抱歉,我真的很忙:(感谢老兄!!!天哪,你是最棒的:D我在一个德国论坛上寻求帮助,但awnser需要几天的时间,然后它就不起作用了,现在我在一个英语论坛上,2分钟后我得到了一个简短而称职的awnser:D再次感谢你帮我从谷歌搜索中解脱出来^^^注意,虽然这可能有效,但生成的值可能出乎意料。System.currentTimeMillis()
返回一个long
值,该值大于整数.MAX\u值
,因此向下转换需要将该值包装成整数。感谢您的快速回答!但是我必须在哪里执行此操作?抱歉,我真的很忙:(感谢老兄!!!天哪,你是最棒的:D我在一个德国论坛上寻求帮助,但awnser需要几天的时间,然后它就不起作用了,现在我在一个英语论坛上,2分钟后我得到了一个简短而称职的awnser:D再次感谢你帮我从谷歌搜索中解脱出来^^^注意,虽然这可能有效,但生成的值可能出乎意料。System.currentTimeMillis()
返回一个long
值,该值大于整数.MAX\u值
,因此向下转换需要将该值包装成整数。感谢您的快速回答!但是我必须在哪里执行此操作?抱歉,我真的很忙:(感谢老兄!!!天哪,你是最棒的:D我在一个德国论坛上寻求帮助,但awnser需要几天的时间,然后它就不起作用了,现在我在一个英语论坛上,2分钟后我得到了一个简短而称职的awnser:D再次感谢你帮我从谷歌搜索中解脱出来^^^注意,虽然这可能有效,但生成的值可能出乎意料。System.currentTimeMillis()
返回一个大于Integer.MAX\u值的long
值,因此向下转换需要将该值包装成整数。