我正在研究Android通知。有没有办法将一个应用程序的所有通知显示为单个通知,并在Android通知窗口中显示数字。点击它会将用户重定向到应用程序中的一个视图,其中包含单独的通知。此外,是否有办法为每个通知设置活动,以便根据点击的通知将用户重定向到相应的活动。
我正在研究Android通知。有没有办法将一个应用程序的所有通知显示为单个通知,并在Android通知窗口中显示数字。点击它会将用户重定向到应用程序中的一个视图,其中包含单独的通知。此外,是否有办法为每个通知设置活动,以便根据点击的通知将用户重定向到相应的活动。
Notification notification = new Notification(R.drawable.logo, name, System.currentTimeMillis());
RemoteViews contentView = new RemoteViews(appContext.getPackageName(), R.layout.custom_layout );
contentView.setTextViewText(R.id.notification_text, Counter);
notification.contentView = contentView;
将活动附加到通知上:
Intent notificationIntent = new Intent(appContext, MyActivity.class);
Bundle bundle = new Bundle();
bundle.putInt(...);
notificationIntent.putExtras( bundle );
notificationIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
PendingIntent contentIntent = PendingIntent.getActivity( appContext, (int)System.currentTimeMillis(), notificationIntent, 0 );
notification.contentIntent = contentIntent;
希望这能有所帮助。